LinqToSQL - 映射出的DataContext有很多表? [英] LinqToSQL - mapping out the DataContext with lots of tables?

查看:326
本文介绍了LinqToSQL - 映射出的DataContext有很多表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直对一个项目,我一直在使用 LinqToSQL ,涉及很多表。所有这些其中有一个的.dbml 文件映射(即只有一个的DataContext )。我这样做的借口是(目前)你不能跨多个数据上下文加盟。例如...

I've been working on a project where I have been using LinqToSQL that involved a lot of tables. All of these where mapped in one .dbml file (i.e. only one DataContext). I did this on the pretense that (currently) you cant join across multiple data contexts. For example...

DB1DataContext db1 = new DB1DataContext();
DB2DataContext db2 = new DB2DataContext();

var query =
    from x in db1.SomeTable
    join y in db2.AnotherTable on x.Id equals y.Id
    select new
    {
        x.Column,
        y.Column
    };



有人认为,这是不是这样的,我应该打破。 DBML 文件分解成更小的独立(即更多的可管理)的数据上下文。我现在已经刚刚成立了一个例子,运行一个类似的查询上面的一个,得到了以下错误...

Someone argued that this isn't so, and I should break the .dbml file down into seperate smaller (i.e more managable) data contexts. I've now just set up an example, run a similar query to the one above and got the following error...

{基地System.SystemException} = {的
查询包含对不同数据上下文定义的项目
的引用。}

base {System.SystemException} = {"The query contains references to items defined on a different data context."}

我很好奇,我失去的东西吗?什么是那里有很多需要映射表的常见做法?你怎么能打破一个.dbml文件?

I am curious, am I missing something? What are the common practices where there are a lot of tables that require mapping? How can you break down a .dbml file?

推荐答案

这在这里问了几次,也没有明确的答案。选中此问题:

This was asked several times here and there is no definite answer. Check this questions:

  • LINQ to SQL: Multiple / Single .dbml per project?
  • Are Multiple DataContext classes ever appropriate?
  • Linq to SQL and large DB model
  • Managing LINQ to SQL .dbml model complexity
  • Best Practices for Managing Linq to SQL Dbml Files?

一些答案​​请参阅此博客帖子:的一个LINQ的寿命到SQL的DataContext

Some answers refer to this blog post: Lifetime of a LINQ to SQL DataContext

这篇关于LinqToSQL - 映射出的DataContext有很多表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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