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;}
}
}
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.
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.
Soufiane1
0 Points
10 Posts
EF 5 Calculated properties not displayed in GridView
Jan 29, 2013 01:27 PM|LINK
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!
Soufiane1
0 Points
10 Posts
Re: EF 5 Calculated properties not displayed in GridView
Jan 30, 2013 05:55 AM|LINK
mr41971
Member
16 Points
78 Posts
Re: EF 5 Calculated properties not displayed in GridView
Jan 30, 2013 02:41 PM|LINK
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.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: EF 5 Calculated properties not displayed in GridView
Jan 31, 2013 12:26 AM|LINK
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.