linq中的错误“查询包含对不同数据上下文中项目的引用". [英] Error in linq "the query contains reference to items in a different datacontext"

查看:68
本文介绍了linq中的错误“查询包含对不同数据上下文中项目的引用".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用两个数据上下文并检索值,但出现以下错误查询包含对不同数据上下文中项目的引用"


I am using two data context and retrieving values i get the following error "the query contains reference to items in a different data context"


dbWebEnrollDataContext dt1 = new dbWebEnrollDataContext();
CommissionsV2DataContext cv1 = new CommissionsV2DataContext();





var getdat=from o in dt.Trade
           join c in cv1.tradevalue on o.id equal c.id 
           select new {o.firstvalue,c.secondvalue};

推荐答案

该问题的解决方案是

创建表的类添加<数据库名称>.< dbo>.<表名称>
如下图所示
The solution to this problem is

The class which creates the table add the <databasename>.<dbo>.<tablename>
as shown below
[Table(Name = "Storedata.dbo.Demo")]
   public partial class Demo : INotifyPropertyChanging, INotifyPropertyChanged


AFAIK,您不能在单个查询中使用2个单独的数据上下文.

AFAIK you cannot use 2 separate data contexts within a single query.

dt.Trade


来自一个数据上下文


comes from one data context

cv1.tradevalue


来自另一个

因此,您需要创建一个包含两个表的数据上下文.然后,您应该能够实现所追求的目标.


comes from another

So you need to create one data context that includes both tables. You should then be able to achieve what you are after.


这篇关于linq中的错误“查询包含对不同数据上下文中项目的引用".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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