简体   繁体   English

实体框架:创建自定义属性

[英]Entity Framework: Creating custom properties

Consider an implementation of the Entity Framework in a DAL assembly. 考虑在DAL程序集中实现实体框架。 I am needing to add a custom read-only property to an entity. 我需要向实体添加自定义只读属性。

Person Class , as defined in the DB, contains fields like: DB中定义的Person类包含以下字段:

PersonID
FirstName
LastName

In the above example, I'd like to make a property called FullName. 在上面的例子中,我想创建一个名为FullName的属性。 It would be the concatenation of 这将是串联

FirstName + " " + LastName;

Can anyone help point out in the .edmx file whereabouts to define this new property? 任何人都可以帮助指出.edmx文件的位置来定义这个新属性吗? Perhaps it's done within the GUI designer? 也许它是在GUI设计器中完成的?

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. 在当前版本的EF中,唯一的方法是在实体的部分类中使用.NET函数。 This means you can't use the new property in LINQ to entities or ESQL, but it works very well otherwise. 这意味着您不能在LINQ中使用实体或ESQL中的新属性,但它的工作方式非常好。

A possible workaround is to do it on the DB server, but the EF would be totally unaware of the relationship between the properties. 可能的解决方法是在数据库服务器上执行此操作,但EF将完全不知道属性之间的关系。

In a future version of the EF, this will be supported in the EDMX . 在EF的未来版本中, 这将在EDMX中得到支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM