我应该在哪里把EF实体和数据标注在asp.net的MVC +实体框架项目 [英] where should I put the EF entity and data annotations in asp.net mvc + entity framework project

查看:95
本文介绍了我应该在哪里把EF实体和数据标注在asp.net的MVC +实体框架项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有EntityFramework4我sqlex press08数据库生成的DataEntity类。此数据上下文通过WCF数据服务/ OData的Silverlight的暴露,并赢得客户的形式

如果数据实体+ EDMX文件(EF4生成)在一个单独的类库中去?

这里的问题然后我会为一些实体的指定数据的注释,然后他们中的一些需要特定的MVC的属性(如CompareAttribute),所以该类库也将引用MVC的DLL。此外,还恰巧是其中将被封装或包裹成在网站上的IIdentity实体用户。因此,它的pretty绑在MVC网站。 或者应该也许去一个Base文件夹中的MVC项目本身?

晴的网站数据围绕数据库驱动,如批准的用户,更改全局设置等实际业务发生在Silverlight和赢得形式的应用程序。

即时通讯使用MVC3 RC2用剃刀。结果
谢谢


解决方案

  

如果数据实体+ EDMX文件(EF4生成)在一个单独的类库去了?


恕我直言,所有这些是特定于某些数据访问技术(在你的情况下,实体框架)的数据访问逻辑应该进入一个单独的程序。应该有引用不存在具体的MVC组件。

在你的ASP.NET MVC应用程序,你会再引用该组件读写视图模型。正是这些视图模式,将包含任何MVC特定属性。然后,您可以将您的模型类,哪些将被传递给视图的视图模型之间进行映射。 AutoMapper 的可用于促进此任务

So I have a DataEntity class generated by EntityFramework4 for my sqlexpress08 database. This data context is exposed via a WCF Data Service/Odata to silverlight and win forms clients.

Should the data entities + edmx file (generated by EF4) go in a separate class library?

The problem here then is I would specify data annotations for a few entities and then some of them would require specific MVC attributes (like CompareAttribute) so the class library would also reference mvc dlls. There also happen to be entity users which will be encapsulated or wrapped into an IIdentity in the website. So its pretty tied to the mvc website. Or Should it maybe go in a Base folder in the mvc project itself?

Mostly the website is data driven around the database, like approve users, change global settings etc. The real business happens in the silverlight and win forms apps.

Im using mvc3 rc2 with Razor.
Thanks

解决方案

Should the data entities + edmx file (generated by EF4) go in a separate class library?

IMHO all data access logic which is specific to some data access technology (in your case Entity Framework) should go into a separate assembly. There should be no MVC specific assemblies referenced there.

In your ASP.NET MVC application you would then reference this assembly and write view models. It is those view models that will contain any MVC specific attributes. Then you could map between your model classes and those view models which would be passed to the view. AutoMapper could be used to facilitate this task.

这篇关于我应该在哪里把EF实体和数据标注在asp.net的MVC +实体框架项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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