在实体框架模型中创建复合属性?
我有两个属性(“FIRST_NAME”和“LAST_NAME”),我需要作为单个属性进行访问(例如“FULL_NAME”)。有没有办法向我的实体模型添加一个包含 FIRST_NAME 和 LAST_NAME 组合值的属性?
I have two properties ("FIRST_NAME" and "LAST_NAME") I need to access as a single property (e.g. "FULL_NAME"). Is there a way for me to add a property to my entity model that contains the combine value of FIRST_NAME and LAST_NAME?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 EF4 创建的模型类通常是部分类,因此您可以选择使用附加属性和方法在单独的文件中扩展这些类。在那里,您可以添加一个仅带有 Getter 的只读属性来返回您的组合全名:
这是一个仅在您的模型类中但未映射到数据库的属性,并且它不作为数据库中的列存在。因为您在单独的文件中创建分部类的这一部分,所以如果您应该更改模型,模型设计者不会触及和覆盖它。
Since the model classes which are created by EF4 are usually
partial
classes you have the option to extend the classes in a separate file with your additional properties and methods. There you could add a readonly property with only a Getter to return your combined full name:This is a property which is only in your model class but not mapped to the database and it doesn't exist as a column in the database. Because you create this part of the partial class in a separate file it is not touched and overwritten by the model designer if you should change the model.