LINQ to SQL:每个项目有多个/单个 .dbml? [英] LINQ to SQL: Multiple / Single .dbml per project?

查看:19
本文介绍了LINQ to SQL:每个项目有多个/单个 .dbml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了 Rick Strahl 关于Linq to SQL DataContext Lifetime Management 希望能找到一些关于如何管理我的 .dbml 文件的答案,因为它们与 DataContext 密切相关.不幸的是,Rick 的文章似乎集中在运行时的DataContext 生命周期,而我的问题是关于在设计时应该如何组织.dbml.

I've read Rick Strahl's article on Linq to SQL DataContext Lifetime Management hoping to find some answers on how I would manage my .dbml files since they are so closely related to DataContext. Unfortunately, Rick's article seems to be focused on DataContext lifetime at runtime though, and my question is concerned with how the .dbml's should be organized at design time.

.dbml 最佳实践"的一般问题 已在此处提问和回答,答案集中在管理 .dbml 的外部工具上.

The general question of 'Best practices with .dbml's' has been asked and answered here, and the answers have focused on external tools to manage the .dbml.

我要问一个更集中的问题:何时以及为什么在基于 LINQ to SQL 的项目中应该有一个 .dbml 文件?

I'm asking a more focused question of when and why should you not have a single .dbml file in your LINQ to SQL based project?

推荐答案

请注意,LINQ2SQL 旨在以简单易行的方式处理数据库与对象的关系.

Please note that LINQ2SQL is intended for simple and easy way to handle database relationship with objects.

不要通过创建多个 .dbml 文件来破坏表关系和工作单元概念.

Do not break table relationship and units of work concepts by creating multiple .dbml files.

如果您需要创建多个 .dbml 文件(我不推荐),请尝试满足以下条件:-

If you ever need to create multiple .dbml files (which i don't recommend), then try to satisfy the following:-

  1. 如果您创建多个数据库,而这些数据库表之间没有关系.
  2. 如果您只想使用这些 .dbml 之一来处理存储过程
  3. 如果您不关心工作单元的概念.

如果你的数据库太复杂,那我会考虑ORM比如NHibernate、EF 4

If your database is too complex, then I would consider ORM such as NHibernate, EF 4

这篇关于LINQ to SQL:每个项目有多个/单个 .dbml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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