问题描述
我从来没有使用过实体框架,我想尝试一些实现它的个人项目,让我的脚变湿。我看到实体可以暴露给表示层。
但我不希望某些字段暴露,字段,如修改日期,创建日期和各种其他数据库字段。
我如何实现业务对象,只暴露我需要的属性,但仍然保持对象可序列化?
与LinqToSql有什么优势?
您可以在EDMX模型中定义一个实体,您可以指定每个属性的setter和getter的可见性,因此如果您不希望ModifiedDate在其他图层中可见,则可以将其简单地指定为内部。
如果您的需求比较复杂,那么可以在实体程序集和业务逻辑组件中访问ModifiedDate,但不能在UI程序集中访问,那么您需要创建另一个将在业务逻辑与UI之间交换的对象逻辑层。
I have never used the entity framework before and i would like to try some personal projects implementing it to get my feet wet.
I see that entities can be exposed to the presentation layer.But i don't want certain fields exposed, fields like modified dates and created dates and various other database fields.
how could i implement Business objects and just expose the properties i need but still keep the objects serializable?
Also what advantages does this have over LinqToSql?
When you define an entity in the EDMX model you can specify the visibility of each property's setter and getter, so if you don't want the ModifiedDate to be visible in other layers, you can simply specify it as internal.
If your requirements are more complicated like the ModifiedDate should be accessible in the entities assembly and the business logic assembly but not in the UI assembly, then you need to create another object which will be exchanged between the business logic and the UI logic layers.
这篇关于实体框架和业务对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!