从实体框架映射到自定义域模型类?
我想知道如何获得实体框架(.NET Framework 3.5 SP1)生成的实体和自定义域模型类之间的自动映射?我知道我可以创建一些数据转换器来在两个世界之间来回转换对象,但是我如何以自动方式完成此操作?
我开始开发我的域模型类,用 验证应用程序块中的验证属性来装饰它们,不能在实体框架自动生成(和刷新)的实体类内部使用。因此,需要在 EF 和域模型之间自动映射(或者至少需要最少的编写代码)......有什么想法吗?
I wonder how could I obtain an automatic mapping between entities generated by entity framework (.NET Framework 3.5 SP1) and custom domain model classes? I know I can create some data converters that translates the objects back and forth between the two worlds, but how could I accomplish this in an automatic way?
I started to develop my domain model classes, decorating them with validation attributes from Validation application block, which cannot be used inside the entity classes automatically generated (and refreshed) by the entity framework. Hence the need for automatically - or at least with minimal written code - mapping between EF and domain model.. any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 EF 1.0 中,Automapper 是一个不错的选择:http://www.codeplex.com/AutoMapper
In EF 1.0, Automapper is a good choice for this: http://www.codeplex.com/AutoMapper
借助 EF 4,现在可以实现这一点,您应该查看有关 EF 的 Julie Lermann 博客。她最近发表了一系列有关 POCO 场景和 EF4 存储库的文章:
http://thedatafarm.com/blog/< /a>
对于 EF 3.5,这很困难,但如果您的类具有相同的属性集,您仍然可以使用 Automapper...
http://automapper.codeplex.com/
With EF 4 this is now possible, You should have a look at Julie Lermann blog about EF . She recently made a whole series of post about POCO scenario and repositories with EF4 :
http://thedatafarm.com/blog/
With EF 3.5 this is hard, but you could still use Automapper if your class have the same set of attributes...
http://automapper.codeplex.com/