locked
EF 5 Calculated properties not displayed in GridView RRS feed

  • Question

  • User1980627298 posted

    Hi everyone!

    I am using asp.net dynamic data (net 4.5 & EF 5). I want to add some calculated properties to my automatically generated entities.

    Entity: ServicetoPerson

    Calculated propertie is: Total

    Problem: I can't see the calculated propertie in the GridView. Any idea?

    Attached iy my Code:

        [DisplayName("Personalzuordnung zum Service")]
        [MetadataType(typeof(ServicetoPerson.ServicetoPersonMetadata))]
        public partial class ServicetoPerson
        {
            
              
            [NotMapped]
            public decimal Total
            {
    
                get{ return 5 * (AK?? default(decimal)); }
                
            }
                 
            
            public class ServicetoPersonMetadata
            {
    
                //[FilterUIHint("ParentTable")]
                [Display(Name = "Mitarbeiter", Order = 1)]
                public Personen Personen { get; set; }
                            
                
                [Display(Name = "Service", Order = 2)]
                public ServiceCatalogue ServiceCatalogue { get ; set; }
    
                [Display(Name = "Kapazität(Wert)", Order = 3)]
                public decimal AK { get; set; }
    
              
                [Display(Name = "Total", Order = 4)]
                public decimal Total {  get; set;}
                               
             }
                  
        }
    
     

    Thx in advance!

     

    Tuesday, January 29, 2013 9:27 AM

Answers

  • User3866881 posted

    Hi,

    As far as I see, you can:

    1) In the constructor of your entitymodel, please do to write some calculation expression directly to assign to the public property.

    2) And then when you initialize the instance, you don't need to assign to the value but leave it blank, becuase it will be auotmatically assigned by the constructor of the EntityModel itself.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 30, 2013 8:26 PM

All replies

  • User1980627298 posted

    Please Help

    Wednesday, January 30, 2013 1:55 AM
  • User1929428035 posted

    I'm not an expert but from my limited understanding DD generates fields based on whats present in the table. So try creating a total column and place your data annotation above this column.

    Wednesday, January 30, 2013 10:41 AM
  • User3866881 posted

    Hi,

    As far as I see, you can:

    1) In the constructor of your entitymodel, please do to write some calculation expression directly to assign to the public property.

    2) And then when you initialize the instance, you don't need to assign to the value but leave it blank, becuase it will be auotmatically assigned by the constructor of the EntityModel itself.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 30, 2013 8:26 PM