在EntityObject和Entity Framework中生成的类之间添加自定义抽象基类 [英] Add custom abstract base class between EntityObject and generated classes in Entity Framework

查看:142
本文介绍了在EntityObject和Entity Framework中生成的类之间添加自定义抽象基类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经生成了一个EDMX项目,我已经建立了我的数据实体类。它们都从System.Data.Object.DataClasses.EntityObject继承。我想做的是从EntityObject继承的另一个抽象类,然后我的数据实体类继承自该新类。



什么是最好的方法来完成这个?



感谢您的帮助。

解决方案

在考虑删除EntityObject时,EF类的工件不应该通过电线曝光。



请使用 DTO pattern



如果您创建新的DTO课程(手动或使用T4模板),并使用类似 AutoMapper 的功能来对数据进行映射



序列化的有效内容将会更简单,更可重用。


I have generated an EDMX project, and I have my data entity classes set up. They all inherit from System.Data.Object.DataClasses.EntityObject. What I would like to do is have another abstract class that inherits from EntityObject, and then my data entity classes inherit from that new class.

What is the best way to accomplish this?

Thank you for any help.

解决方案

You are right in thinking about removing EntityObject, artifacts of EF classes should not get exposed over the wire.

Please, please, please use the DTO pattern for objects that get passed over the wire.

If you create new DTO classes (manually or using a T4 template) and use something like AutoMapper to map the data back and forth.

The serialized payloads will be far simpler and more reusable.

这篇关于在EntityObject和Entity Framework中生成的类之间添加自定义抽象基类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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