LINQ到SQL:有多少datacontexts? [英] Linq-to-SQL: how many datacontexts?

查看:92
本文介绍了LINQ到SQL:有多少datacontexts?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有300表的SQL Server 2008数据库。我要设计的应用程序是一个Windows窗体应用程序,.NET 3.5,C#。

I have a SQL Server 2008 database with > 300 tables. The application I have to design is an Windows Forms app, .NET 3.5, C#.

这与LINQ到SQL工作的最佳方法是什么?

Which is the best way to work with Linq-to-SQL ?

我打算为各业务实体的DataContext的。

I intend to make a datacontext for each business entity.

有什么问题吗?

我需要知道,如果用这种工作方式LINQ到SQL有任何不利或可能会导致性能问题?

I need to know if this way of working with Linq-to-SQL has any disadvantage or can create performance issues ?

谢谢。

推荐答案

您通常应该有每个数据库1单DBML文件(=数据上下文)。你当然应该不是每个企业实体创建一个的DataContext ,因为这样做会使你失去大部分的LINQ到SQL有用的功能,如内存交易(工作单位),延迟加载,做LINQ查询在多个实体。

You should typically have 1 single DBML file (=data context) per database. You should certainly not create a DataContext per business entity, because doing this would make you lose most of the useful capabilities of LINQ to SQL, like memory transactions (unit of work), lazy loading, and doing LINQ queries over multiple entities.

您有这意味着很多实体的相当大的模型(+300表)。很多实体是不是一个大问题,除了LINQ to SQL设计。使用这样的大模型设计师可以很烦人。这可能是一个原因来分割在多个子域的域(每一个DBML文件),但肯定每个实体没有之一。但是,请记住,你失去在域的边界L2S能力。

You have a pretty big model (+300 tables) which means a lot of entities. A lot of entities is not a big problem, except for the LINQ to SQL designer. Using the designer with such big models can be pretty annoying. This can be a reason to split a domain in multiple sub domains (with each a DBML file), but certainly not one per entity. However, keep in mind that you loose the L2S capabilities at the boundaries of the domains.

在过去我劝一个团队,谁分裂他们+150实体领域5 DBML文件,将它们合并到一起,以一个单一的DBML。编辑模型的疼痛起来,但是使用多的痛苦的DataContext 取值就走了,这大大降低了整体的痛苦他们。

In the past I advised a team, who had split up their +150 entities domain in 5 DBML files, to merge them back together to a single DBML. The pain of editing the model went up, but the pain of using multiple DataContexts went away, which lowered the overall pain drastically for them.

这篇关于LINQ到SQL:有多少datacontexts?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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