Last post Jun 27, 2012 08:00 AM by biga
Jun 26, 2012 01:20 PM|biga|LINK
For my dynamic data application using Domain Service and Entity Framework, I have a model that includes the following entities:
Client -> ClientProducts -> ReleaseHistory
The ReleaseHistory page shows the foreign key for the ClientProducts table as a number (the id). Normally to include the readable name for a foreign key, I use .Include() in the DomainService class, e.g.
public IQueryable<ClientReleaseHistory> GetClientReleaseHistories()
return ((ObjectQuery<ClientReleaseHistory>)(this.ObjectContext.ClientReleaseHistories.OrderBy(c => c.ID))).Include("ClientProduct").Include("ClientProduct.Product");
This works fine where there is only one item in the .Include() call, but where I need to traverse more than one entity and have a dot separated list in .Include, it doesn't work (just displays the id).
Any ideas on how I would show the Product Name instead of the foreign key ID in this case. I thought of adding code to the GridView RowDataBound event, but I don't know of a way to access the GridView's controls for DynamicData. The other option would be
to use a custom field template, but I wondered if there was an easier way.
Jun 27, 2012 08:00 AM|biga|LINK
Sorry to answer my own question!
I realised I can solve this by adding a public property to the public partial class in the DomainService.metadata:
public partial class ClientReleaseHistory
public string Product
This then causes an additional Product column to appear showing the ProductName from the Product entity.