Wednesday, March 23, 2011

Entity Framework: Creating custom properties

Consider an implementation of the Entity Framework in a DAL assembly. I am needing to add a custom read-only property to an entity.

Person Class, as defined in the DB, contains fields like:

PersonID
FirstName
LastName

In the above example, I'd like to make a property called FullName. It would be the concatenation of

FirstName + " " + LastName;

Can anyone help point out in the .edmx file whereabouts to define this new property? Perhaps it's done within the GUI designer?

From stackoverflow
  • In the current version of the EF, the only way to do this is as a .NET function in your partial class for the entity. This means you can't use the new property in LINQ to entities or ESQL, but it works very well otherwise.

    A possible workaround is to do it on the DB server, but the EF would be totally unaware of the relationship between the properties.

    In a future version of the EF, this will be supported in the EDMX.

0 comments:

Post a Comment