EF 5.0模型优先-如何制作未映射的属性 [英] EF 5.0 Model First - How To Make Not Mapped Properties

查看:160
本文介绍了EF 5.0模型优先-如何制作未映射的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Code First具有[NotMapped]属性,用于不应该映射的属性:在模型优先模式下如何实现相同的目的?

Code First has the attribute [NotMapped] for properties which are not to be mapped: how would one achieve the same thing in model-first mode?

推荐答案

NotMapped 属性不属于映射。当使用模型优先方法时,EDMX表示映射,因此映射了图中定义的每个属性。如果要具有非映射属性,则不得在图中定义它。 EF的代码生成所生成的所有类都是局部的,因此您只需要创建自己的类的局部部分(该部分必须与所生成的部分位于同一名称空间和程序集中)并在代码中定义非映射属性。

NotMapped properties are not part of your mapping. When the model first approach is used EDMX represents the mapping so every property defined in the diagram is mapped. If you want to have non-mapped property it must not be defined in the diagram. All classes generated by EF's code generation are partial so you only need to create your own partial part of the class (it must be in the same namespace and assembly as generated part) and define your non-mapped property in code.

这篇关于EF 5.0模型优先-如何制作未映射的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆