I'm trying to display calculated fields in my Dynamic Data Entities site. I have generated my EDMX file from an existing database, and have added customizations in a separate file using partial classes. I want the calculated fields to show up on the Display and List screens.
I've seen tons of examples online where people supposedly have this working; however, most of them are focused on Code-First approaches instead of Database-First. I do not have the option of Code-First as the database is already finished.
I have tried various data annotations including:
[ScaffoldColumn(true)]
[NotMapped]
[ReadOnly]
[Display(AutoGenerateField=true)]
I've also tried following the MetadataType in the following format:
[MetadataType(typeof(ProductMetadata))]
public partial class Product
{
[ScaffoldColumn(true)]
[NotMapped]
public decimal CostPerUnit
{
get
{
return TotalCost / (decimal)TotalUnits;
}
}
}
public class ProductMetadata
{
[ReadOnly(true)]
[Display(Name = "[Cost Per Page]", AutoGenerateField = true, AutoGenerateFilter = false)]
[UIHint("Number")]
public object CostPerUnit { get; set; }
}
The code above compiles just fine for me. The display and list forms both display columns in the Product table, and my other annotations (not listed), show up just fine. None of the calculated fields are being displayed. There are no error messages.
Am I doing something wrong, or approaching this problem the wrong way? Are EntityFramework 5.0 and Dynamic Data not able to accomplish my goals? If the latter, does EF 6.0 have what I need?
Edit 2014-07-11:
I've switched to Entity Framework version 6 and tried a code-first approach. I was still unable to create a calculated field in code-behind that would show up in a dynamic data site.
Is there any way whatsoever to include code-behind properties of an entity object in a dynamic data website? I am 100% fine with rewriting and overriding other classes in the framework to accomplish this goal (in fact, I've tried to with minimal success).