本文介绍了Linq to SQL和大型数据库模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是SQL新手的Linq,所以请放心:).

First, I am Linq to Sql newbie, so please be gentle :).

我有过去3.5年开发的现有ASP.Net应用程序.它的下面有相当大的数据模型,大约有350个表.我正在尝试使用Linq to SQL做一些新的事情.

I have existing ASP.Net application developed over last 3.5 years. It has pretty big data model underneath, around 350 tables. I am trying to do some new things with Linq to SQL.

第一印象是linq设计器和SqlMetal是为不大于NorthWind示例的数据库构建的.这是我遇到的一些问题:

First impression is that linq designer and SqlMetal are built for databases not bigger than NorthWind example. Here are some problems I have:

  1. 我有很多地方(库存,发票,生产等)需要的表Products.如果将表Products放在每个dbml文件中,则linq设计器将在每个dbml文件中创建Product类.我不要我只想一个Product课.
  2. 我有有关运输的DataContext.它需要大约40张桌子.这使得dbml文件非常难以管理.有没有办法创建较小的dbml文件,然后将它们(作为参考)包含到一些主要" dbml中?
  1. I have table Products that is needed in lots of places (inventory, invoicing, production, ...). If I put table Products in each dbml file, linq designer is going to create Product class in each of them. I don't want that. I want to only one Product class.
  2. I have DataContext about shipping. It needs around 40 tables. This makes dbml file very hard to manage. Is there a way to create smaller dbml files and then include them (as reference) into some "major" dbml?

就目前而言,我真的很喜欢Linq,但我认为它仍然严重缺乏用于10张以上桌子的设计工具.

For now, I really like Linq, but I think it is still seriously lacking design tool for anything bigger than 10 tables.

我现在的解决方案是使用Linq设计器构建较小的模型,然后手动合并它们(添加属性和引用),因此将生成大量代码,但也将需要大量手动工作.

My solution now is building smaller models with Linq designer and then manually merging them (adding properties and references), so lots of code will be generated, but there will also be lots of manual work.

我错过了什么大事吗?还是这种与Linq到Sql的往来?

Did I miss something big or is this current state of affair with Linq to Sql?

推荐答案

好吧,我的解决方案是使用SQLMetal的/code选项在.cs文件而非DBML文件中创建普通类,并在单独的文件以扩展生成的ORM类.

well, my solution was to use SQLMetal's /code option to create plain classes in a .cs file instead of a DBML file, and use partial classes in a separate file to extend the generated ORM classes.

我知道这不能解决您将数据库的各个部分拆分为不同的ORM程序集的问题-我只是发现,没有DBML/Designer的麻烦,在.cs文件中管理大量类并不是太糟糕了.

I know that doesn't solve your issue of splitting parts of your database into different ORM assemblies - I just found that without the headache of the DBML / Designer, managing a large number of classes in a .cs file wasn't too bad.

这篇关于Linq to SQL和大型数据库模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 22:47