我应该将 EF 实体和数据注释放在 asp.net mvc 中的哪里?实体框架项目
所以我有一个由 EntityFramework4 为我的 sqlexpress08 数据库生成的 DataEntity 类。此数据上下文通过 WCF 数据服务/Odata 公开给 silverlight 和 win forms 客户端。
数据实体 + edmx 文件(由 EF4 生成)是否应该放入单独的类库中?
这里的问题是我会为一些实体指定数据注释,然后其中一些实体需要特定的 MVC 属性(如 CompareAttribute),因此类库也会引用 mvc dll。也有一些实体用户会被封装成网站中的IIdentity。所以它与 mvc 网站紧密相关。 或者应该放在 mvc 项目本身的 Base 文件夹中吗?
大多数网站是围绕数据库驱动的数据,例如批准用户、更改全局设置等。真正的业务发生在 silverlight 中并获胜表单应用程序。
我将 mvc3 rc2 与 Razor 一起使用。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
恕我直言,特定于某些数据访问技术(在您的情况下是实体框架)的所有数据访问逻辑都应该放入单独的程序集中。那里不应该引用 MVC 特定的程序集。
然后,在 ASP.NET MVC 应用程序中,您将引用此程序集并编写视图模型。这些视图模型将包含任何 MVC 特定属性。然后,您可以在模型类和将传递给视图的视图模型之间进行映射。 AutoMapper 可用于促进此任务。
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.