再次为LINQ to SQL或Entity Framework提供新的MVC 3项目 [英] Once again LINQ to SQL or Entity Framework for new MVC 3 project

查看:249
本文介绍了再次为LINQ to SQL或Entity Framework提供新的MVC 3项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我的背景是:MS SQL Server上的相当大的数据库(约100个表,每个约10-20列),它始终将首先是SQL Server和数据库。



我在WebForms和LINQ to SQL方面有一些经验,但我厌倦了编写所有提到的表格的表单,所以mvc 3剃刀与它的脚手架只是催眠我,我在做梦为我生成所有的表单



但它出来了(或者也许,我没有得到什么),那个脚手架只适用于EF DbContext。对于L2S,它表示不受支持的DbContext。
我已经尝试使用LinqToSql脚手架(在PM控制台中输入Set-DefaultScaffolder Repository LinqToSqlScaffolding.Repository)的MvcScaffolding,但仍然不是L2S相关映射的歌曲。



所以第一个问题是 - 有一种方法(一个稳定的方式)将Linq的脚手架添加到SQL类



现在我已经调查了一些发现所有关于L2S vs EF的主题,说同样的 - L2S先行,所以它更加稳定,EF还很年轻,但是这是一个很长的镜头,它是灵活的,可映射的等等。



我没有得到的第一件事是我应该如何映射我的企业数据库的灵活模型?
我已经使用一个设计器为EF DbContext生成类,就像我以前做过的L2S一样,而L2S则由〜42000行组成。
现在我必须搜索一些实体属性,并为它们设置一些属性,如必需,显示和范围,但设计者将覆盖它们。
我知道如何实现部分类或部分方法,但不知道在外部文件中添加属性,因为设计人员无法覆盖它们。
i猜测,这应该是第二个问题。



如果我应该用手将我的企业数据库映射到EF,以保持灵活... o_O
〜〜42000行自动生成的班级吓唬我到蜜蜂!真的有必要吗?

解决方案


  1. 实体框架最近有所进步。我认为它是稳定的。与MVC3的新整合非常出色。

  2. 关于添加自定义的DataAnnotation属性进行验证,这篇文章描述了一种使用EF的方法。 (向下滚动到底部。)由于您无法修改生成的属性,因此使用自定义元数据映射来应用它们。

  3. 您真的希望让它尽可能地生成为你,不要疯了。 EF具有与L2S非常相似的设计表面,您可以像您想要的那样简单或复杂。

此外,MVC3将生成基于任何对象模型的强力类型视图。主要区别在于,使用EF,它将为您连接一切,而使用自定义POCO或L2S,您必须自己完成所有的管道。 (从这个角度来看,这与MVC的早期版本完全一致。)


first of all, my background is: pretty large database (~100 tables with ~10-20 columns each) on MS SQL Server and it's always gonna be SQL Server and database first.

i have some experience in WebForms and LINQ to SQL, but i'm sick of constructing forms for editing all that mentioned tables, so mvc 3 razor with it's Scaffolding just hypnotized me, and i'm dreaming of it generates all that forms for me

but it comes out (or, maybe, i don't get something), that scaffolding works only for EF DbContext. for L2S it says 'unsupported DbContext'. i've tried MvcScaffolding with LinqToSqlScaffolding (typed 'Set-DefaultScaffolder Repository LinqToSqlScaffolding.Repository' in PM console), but still not a sing of L2S related mapping.

So the first question is - "Is there a way (a stable way) to get scaffolding for Linq to SQL classes"

now i've had investigated some and found all of that topics about L2S vs EF, saying the same - "L2S came first, so it's more stable, and EF is still young, but it's a long shot, it's flexible, mappable and so on".

the first thing i don't get is how should i map that flexible model for my enterprise database? i've used a designer to generate class for EF DbContext, as i've done before for L2S, and as for L2S it consist of ~42000 lines. now i have to search for some entity properties there and set some attributes for them , like 'Required', 'Display' and 'Range', but designer will overwrite them. i know how to implement partial class or partial method, but not aware of making any additions to properties in external file, for designer couldn't overwrite them. i guess, this should be the second question.

and if i should map my enterprise database to EF by hands, to keep it flexible... o_O that ~42000 lines of auto-generated class scares me to bee-gees! is it really necessary?

解决方案

  1. Entity Framework has advanced quite a bit lately. I'd consider it "stable". The new integration with MVC3 is outstanding.
  2. As for adding custom DataAnnotation attributes for validation, this article describes an approach using EF. (Scroll down to the bottom.) Since you can't modify the generated properties, it uses a custom metadata mapping to apply them.
  3. You really want to let it generate as much as possible for you, to keep from going insane. EF has a design surface very similar to L2S and you can get as simple or as complicated as you want.

Also, MVC3 will generate strongly-typed views for you based on any object model. The primary difference is that, with EF, it will wire up EVERYTHING for you, whereas with custom POCO or L2S you have to do all of the plumbing yourself. (From that standpoint, this works exactly like earlier versions of MVC.)

这篇关于再次为LINQ to SQL或Entity Framework提供新的MVC 3项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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