English 中文(简体)
• 如何验证作为DbContext生成的作为p.net mvc的EF4.0模型?
原标题:How to validate EF 4.0 model with generated DbContext in asp.net mvc?

页: 1 我仍然希望使用EF 4.0、的化chem模型,但我也希望第4.1号框架的预报和灵活性。

因此,在我的申请中,我从目前的EF4.0模式中添加了DbContext代号。

www.un.org/Depts/DGACM/index_spanish.htm 现在,我的问题是,我有哪些选择来证实我的DbSet(EF 4.1)模式,而没有它们被抹去?。

数据年限似乎在减少,因为每次都使用。 我更新了我的视觉模型,在我的所有修改中都做了总结。

  • I have heard about partial classes, but that seems to be really messy.
  • I don t really want to do validations on my controller.
  • I want to make this scalable so I can easily transfer my classes from asp.net MVC to WPF and etc.

Is there a way to do this? Validation repository? Seperate validation layer? Validation inside the repository layers? Examples would be appreciated too.

请帮助我。 感谢:

最佳回答

利用模板生成器,似乎可以做以下工作之一:

  1. Create a buddy class for each of your entities, and define the buddy class by naming convention in the template.
  2. Figure a way to gen the data annotations, by storing them in a separate source or something.

或者,使用一个单独的层次。 如果你使用储存库,你可以在那里进行验证。 我选择了一家Orm Validation工厂,该工厂采用与某个实体(固定或动态)相匹配的规则,而工厂则从事这项工作(因为这更符合单项责任原则)。

HTH.

问题回答

In my project I mix both 4.1 and 4.0 contexts. It is possible to do a slow migration. There is also a entity framework 4.1 reverse engineer extension that can be added to visual studio. (to let you use 4.1 by code generating poco objects + mappings from your existing database).

我不建议建立一个DbContext,使edx生成的模型从4.0。 您也放宽了继承标语/dbcontext、继承财产(浏览版、读物)以及控制波科物体的好处(因此,你不必担心部分元件和元数据类型,如4.0)。

贵方关于验证以牛奶 created为生的化学制品的问题:

因此,在更新你需要使用的元数据模型时,数据说明被彻底删除。 类型属性。

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.metadatatypeattribute.aspx

例如





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签