ORM Entities vs. Domain Entities under Entity Framework 6.0
I stumbled upon the following two articles First and Second in which the author states in summary that ORM Entities and Domain Entities shouldn't be mixed up.
I faced exactly this problem at the moment as I code with EF 6.0 following the Code First approach. I use the POCO classes as entities in the EF as well as my domain/business objects. But I find myself frequently in the situation where I define a property as public or a navigation property as virtual only because the EF Framework forces me to do so.
But I don't know what to take as the bottom line of the two articles? Should I really create for example a CustomerEF class for the entity framework and a CustomerD for my domain. Then create a repository which consumes CustomerD maps it to CustomerEF do some queries and than maps back the received CustomerEF to CustomerD. I thought EF is all about mapping my domain entities to the data.
So please give me some advise. Do I overlook an important thing the EF is able to provide me with? Or is this a problem which can not completely solved by the EF? But in the latter case what is a good way to manage this problem?
43 down vote accepted
I agree with the general idea of these posts. An ORM class model is part of a data access layer first and foremost (even if it consists of so-called POCOs). If any conflict of interests arises between persistence and business logic (or any other concern), decisions should always be made in favor of persistence. However, as software developers we always have to balance between purism and pragmatism. Whether or not to use the persistence model as a domain model depends on a number of factors:
And more, undoubtedly. So I would always try to be a pragmatist. If entity classes do a decent job, go for it. If the mismatch is too large, create a business domain for appropriate parts of the business logic. I would not slavishly follow a (any) design pattern just because it is a good pattern. Contrary to what is said in the post, it requires a lot of maintenance to map an entity model onto a business model. When you find yourself creating myriads of business classes that are almost identical to entity classes it's time to rethink what you're doing. |
ORM Entities vs. Domain Entities under Entity Framework 6.0的更多相关文章
- [EF2]Sneak Preview: Persistence Ignorance and POCO in Entity Framework 4.0
http://blogs.msdn.com/b/adonet/archive/2009/05/11/sneak-preview-persistence-ignorance-and-poco-in-en ...
- Entity Framework 6.0 入门系列 第一篇
Entity Framework 6.0 入门系列 第一篇 好几年前接触过一些ef感觉不是很好用,废弃.但是 Entity Framework 6.0是经过几个版本优化过的产物,性能和功能不断完善,开 ...
- 开发 ASP.NET vNext 续篇:云优化的概念、Entity Framework 7.0、简单吞吐量压力测试
继续上一篇<开发 ASP.NET vNext 初步总结(使用Visual Studio 2014 CTP1)>之后, 关于云优化和版本控制: 我本想做一下MAC和LINUX的self-ho ...
- Entity Framework 5.0系列之Code First数据库迁移
我们知道无论是"Database First"还是"Model First"当模型发生改变了都可以通过Visual Studio设计视图进行更新,那么对于Cod ...
- 精进不休 .NET 4.5 (12) - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性
[索引页][源码下载] 精进不休 .NET 4.5 (12) - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性 作者:weba ...
- 在Entity Framework 4.0中使用 Repository 和 Unit of Work 模式
[原文地址]Using Repository and Unit of Work patterns with Entity Framework 4.0 [原文发表日期] 16 June 09 04:08 ...
- Entity Framework 5.0
今天 VS2012 .net Framework 4.5 Entity Framework 5.0 三者共同发布了. ( EF5 Released ) 在介绍新特性之前,先与大家回顾一下EF版 ...
- 云优化的概念、Entity Framework 7.0、简单吞吐量压力测试
云优化的概念.Entity Framework 7.0.简单吞吐量压力测试 继续上一篇<开发 ASP.NET vNext 初步总结(使用Visual Studio 2014 CTP1)>之 ...
- 浅析Entity Framework Core2.0的日志记录与动态查询条件
前言 Entity Framework Core 2.0更新也已经有一段时间了,园子里也有不少的文章.. 本文主要是浅析一下Entity Framework Core2.0的日志记录与动态查询条件 去 ...
随机推荐
- Keil 4 与Proteus 7.8联调
实验环境: windows 8.1 pro with Keil 4 and Proteus 7.8 both cracked. 步骤: 下载联调工具Vdmagdi,安装. keil下Option/De ...
- ubuntu漂亮主题
桌面看腻了?试试这 4 款漂亮的 Linux 图标主题吧 http://linux.cn/article-4332-1.html Flatabulous https://github.com/anmo ...
- hdu 5646 DZY Loves Partition 二分+数学分析+递推
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5646 题意:将n分成k个正整数之和,要求k个数全部相同:并且这k个数的乘积最大为多少?结果mod 1e^9 ...
- 面向站长和网站管理员的Web缓存加速指南
详细了解HTTP缓存控制及为什么要缓存. 英文版: http://www.mnot.net/cache_docs/ 中文版:http://www.chedong.com/tech/cache_docs ...
- 在Windowx下创建以点开头的.hatccess文件
转自:在Windowx下创建以点开头的.hatccess文件 Windows有些目录名是不能创建的,有一些文件按照常规方式也是不能创建的,如在Windows下创建文件夹名为con的目录就不行,在win ...
- MYSQL中插入数据时出现的问题:
问题: mysql',default,default); ERROR (HY000): Incorrect string value: 解决方案: 首先查看自己的数据表情况: mysql> SH ...
- join的一对多,去除重复,排序优先的group方法
想将问题列表按照最新回答来排列.但问题和回答是分拆在两张表来存放的.所以,要完成上述需求,需从主表“问题”取显示数据,但是得按照次表(回答)的更新日期来排序. 用join来做,始终无法去除重复,折腾了 ...
- 移动开发:初学 iOS-UIViewController 心得
初学 iOS,本文翻译了一些 iOS 官网上的 UIViewController 的知识点,如有不到位或不正确的地方,还请指正: 本文所介绍的内容的目标: 理解content view control ...
- A9两款芯片管脚数目
Exynos 4412 bga786; S5P4418 bga513
- SpeeDO —— 并行深度学习系统
SpeeDO —— 并行深度学习系统 摘要: 最近,AlphaGo又带起了一波深度学习的热潮.深度学习在很多领域都大幅提高了模型的精度,使得很多以前在实验室中的技术得以运用到日常的生活之中.然而, ...