再一次的LINQ to SQL或实体框架新的MVC 3项目 [英] Once again LINQ to SQL or Entity Framework for new MVC 3 project

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

问题描述

首先,我的背景是:pretty大型数据库(约100桌与10-20〜每列)MS SQL Server上,它总是会是SQL Server和数据库第一个

我在WebForms和LINQ to SQL的一些经验,但我生病了构建编辑一切形式的提到的表,因此MVC 3剃须刀与它的脚手架只是催眠我,我梦想着它产生的一切对我来说形式

但它出来(或者,也许,我没有得到的东西),该脚手架仅适用于EF的DbContext。对于L2S它说'不支持的DbContext。
我试过用MvcScaffolding LinqToSqlScaffolding(类型设置 - DefaultScaffolder库LinqToSqlScaffolding.Repository在PM控制台),但仍然不是一个唱L2S相关的映射。

所以,第一个问题是 - 有没有办法(稳定的方式),以获得脚手架LINQ to SQL类

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

我不明白的第一件事是我应该如何映射为我的企业数据库灵活的模型?
我用一个设计师产生类EF的DbContext,因为我已经为L2S之前完成,并作为L2S它包含〜42000线。
现在我要寻找一些实体属性存在,并为他们设置一些属性,如必需的,显示和范围,但设计师会覆盖它们。
我知道如何实现局部类或部分的方法,但不知道做任何补充性外部文件中,设计师不能覆盖他们。
我想,这应该是第二个问题。

我若用手我的企业数据库映射到EF,使其保持弹性... O_O
那〜42000行自动生成的类的恐吓我蜂Gees的!是不是真的有必要吗?


解决方案

  1. 实体框架拥有先进颇有几分最近。我会认为这是稳定。与MVC3新的整合是优秀的。

  2. 审定
  3. 至于添加自定义属性DataAnnotation,的这篇文章介绍使用EF的方法。 (向下滚动至底部。)既然你不能修改生成的属性,它使用一个自定义的元数据映射到应用它们。

  4. 您真的要让它产生尽可能多的你,从去疯狂继续。 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或实体框架新的MVC 3项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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