实体框架和业务对象 [英] Entity Framework And Business Objects

查看:290
本文介绍了实体框架和业务对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有使用过实体框架,我想尝试一些个人项目实现它让我的脚湿。

I have never used the entity framework before and i would like to try some personal projects implementing it to get my feet wet.

我看到实体可以接触到presentation层。
但我不想暴露某些领域里,如修改日期和创建日期和其他各种数据库字段的字段。

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?

也做这个有什么好处超过LinqToSql?

Also what advantages does this have over LinqToSql?

推荐答案

当你定义在EDMX模型中的实体,您可以指定每个属性的setter和getter的知名度,所以如果你不希望ModifiedDate可见在其他层,你可以简单地将其指定为内部。

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.

如果您的需求比较复杂,如ModifiedDate应在装配实体和业务逻辑组件访问,但不是在UI组件,那么你需要创建一个将业务逻辑和UI逻辑之间交换另一个对象层。

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.

这篇关于实体框架和业务对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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