简体   繁体   English

像EF Designer这样的映射工具,但用于数据对象?

[英]Mapping Tool like EF Designer but for Data objects?

In trying to separate my domain layers and GUI and looking into all the different ways to do that, one thing that I keep asking is why is this so difficult? 在尝试分离域层和GUI并研究实现该目标的所有不同方法时,我一直在问的一件事是为什么这是如此困难? Why all the extra code for data obejcts and then all the extra mapping of properties copying values in and out etc. Shouldn't theere be an easier way? 为什么要为数据对象提供所有额外的代码,然后为属性进行所有额外的映射,从而将值复制进出等等。

Then I remeembered when i used to wite small littler db app using MS Access and, Access has the concept of a Dynaset, basically a Dynaset is a View, just like an SQL Server View, except it is an updateable view. 然后,当我以前使用MS Access来访问小型littler db应用程序时,我就进行了回顾,Access具有动态集的概念,基本上,动态集是一个视图,就像SQL Server视图一样,只是它是可更新的视图。 So, a MS Access form would be based of the View/Dynaset and therefore would not have to know the details of all the individual tables involved. 因此,MS Access表单将基于“视图/动态集”,因此不必知道所涉及的所有单个表的详细信息。 Sounds like the Data objects pattern to me. 在我看来,听起来像是数据对象模式。 Now, since Access has had this for 2 decades, shuoldn't there be a similar Dynaset, View, Mapping tools for Entity Framework, one that abstracts away the entities from the presentation? 现在,由于Access已经使用了20年,因此是否应该没有针对Entity Framework的类似的Dynaset,View,Mapping工具,该工具可以将实体从演示文稿中抽象出来? Is there one I am not aware of? 有我不认识的人吗? 3rd party? 第三方?

Thoughts on this? 有这个想法吗?

If I understand you correctly, you may be looking for Entity Framework with POCO entities. 如果我对您的理解正确,那么您可能正在寻找带有POCO实体的实体框架。 You can find templates for them in the online gallery for templates (when you Add New Item in the project). 您可以在在线模板库中找到模板的模板(在项目中添加新项时)。 Alternatively you can use right-click in your .edmx design view, select "Add code generation item" and pick the Fluent Generator. 或者,您可以在.edmx设计视图中单击鼠标右键,选择“添加代码生成项”,然后选择Fluent Generator。

These methods create multiple files instead of the default all-in-one EF generated file. 这些方法将创建多个文件,而不是默认的多合一EF生成文件。 One such file is the DbContext (as opposed to ObjectContext), one contains only entities (in the form of regular C# objects, no attributes or anything, just plain objects) and the last contains generated mapping in the form of fluent rules. 一个这样的文件是DbContext(与ObjectContext相反),一个文件仅包含实体(以常规C#对象的形式,没有属性或任何东西,仅是普通对象),最后一个包含以流畅规则的形式生成的映射。

In this phase you can de-couple the entities file from its template and move it to another assembly. 在此阶段,您可以将实体文件与其模板分离,然后将其移动到另一个部件。 And voila, you have entities independent on the EF infrastructure. 瞧,您拥有独立于EF基础架构的实体。 You can just pass the context these entities like you would before, and it'll do mapping by itself. 您可以像以前一样传递这些实体的上下文,并且它将自己进行映射。

Alternatively you can use tool like AutoMapper , but you'll have to provide the mapping manually, which is a lot of work, but may be good in some cases. 另外,您可以使用AutoMapper之类的工具,但是您必须手动提供映射,这是很多工作,但是在某些情况下可能会很好。

Good design requires work. 好的设计需要工作。 If it was easy, everyone would do it automatically. 如果简单的话,每个人都会自动做到。 After all, everyone wants to do the least amount of work possible. 毕竟,每个人都想做最少的工作。

All the things you are complaining bout are part of the good design process, and there is no getting around them if you want a good design. 您抱怨的所有事物都是好的设计过程的一部分,如果您想要一个好的设计,那就无所不用其极了。

If you want to take shortcuts, then by all means, skip them. 如果要使用快捷方式,请务必跳过它们。 It's your code. 这是您的代码。 nothing requires you to do things any specific way. 没有什么要求您以任何特定方式来做事。

Access can do a lot of things because it's a desktop application, not a web application. Access可以做很多事情,因为它是桌面应用程序,而不是Web应用程序。 Web applications are fundamentally different from desktop applications in how you design them, how they work, and what issues you face with them. Web应用程序与桌面应用程序的根本不同之处在于您如何设计它们,它们如何工作以及面临哪些问题。 For instance, the fact that you have a stateless environment and cannot keep result set from request to request makes many of the things people take for granted in Access impossible to do in a web app. 例如,您拥有无状态的环境,并且无法在请求之间保留结果集,这一事实使人们无法在Web应用程序中完成人们在Access中理所当然的事情。

Specifically, if you want to use views, you can do so. 具体来说,如果要使用视图,则可以使用。 Views are updateable if they are properly designed, but typically require update statements that only affect one table in the view). 如果对视图进行了适当的设计,则它们是可更新的,但是通常需要仅影响视图中一个表的更新语句。 EF can work with views as well, but it has a lot of quirks you must deal with. EF也可以使用视图,但是您必须处理很多怪癖。

The data mapper pattern has emerged as a common pattern in web design because it's the easiest and straight forward way to have clean separation of concerns between layers and/or tiers. 数据映射器模式已成为Web设计中的常见模式,因为它是在层和/或层之间进行清晰的关注分离的最简单直接的方法。 I suggest you find ways to make them work within your development process. 我建议您找到使它们在开发过程中起作用的方法。

It may also be that MVC is not the most appropriate framework for you to use. 也可能是MVC不是最适合您使用的框架。 It sounds more like you want to build Web apps the way you did Acceess, in which case Visual Studio Lightswitch may be a better choice for you. 听起来更像是您要像使用Acceess一样构建Web应用程序,在这种情况下,Visual Studio Lightswitch可能是您更好的选择。

http://msdn.microsoft.com/en-us/library/ff851953.aspx http://msdn.microsoft.com/en-us/library/ff851953.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM