查询包含对不同数据上下文定义项的引用 [英] The query contains references to items defined on a different data context

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

问题描述

我看了夫妇在另一#1的职位,但我的问题很简单,不同。我有2个独立的数据库,而这就是为什么我有两个单独的DataContext。这里是我的查询中,我传递参数,并将其绑定到我的GridView的:

I read couple of another posts in Stackoverflow but my problem is simple and different. I have 2 separate databases and thats why I have two separate Datacontext. Here is my query in which I am passing parameters and binding it to my GridView:

if (Session["EntitySelected"] == null)
{
    MessageBox.Show("Please Select an Entity first!");
    Response.Redirect("~/FrontEnd/List.aspx");
}
int getEntity = Int16.Parse(Session["EntitySelected"].ToString());
this.Label3.Text = "You Selected Entity: " + (string)Session["EntitySelected"];

dbWebEnrollDataContext dt1 = new dbWebEnrollDataContext();
CommissionsV2DataContext cv1 = new CommissionsV2DataContext();
var td = from s in cv1.Entity_Product_Points
         join r in dt1.PlanMasters on s.Product_ID equals r.Product_ID
         where s.Entity_ID == getEntity
         select new
         {
             s.Product_ID,
             r.PlanName,
             s.HiCommission,
             s.HiCommissionOld,
             s.LowCommission,
             s.LowCommissionOld
         };
gvShowComm.DataSource = td;
gvShowComm.DataBind();

正如预期的那样被扔我这个错误。但是,我也一样,而我添加记录到1个数据库的表。它插入行,但也抛出了同样的错误。请告诉我四处参观一下?谢谢!

As expected it is throwing me this error. But I did the same while I am adding a record into the a table of 1 database. It is inserting row but also throwing the same error. Whats the look around? Thank you!

推荐答案

我不认为你应该做跨两个数据上下文的连接。从你的LINQ查询的外观,你甚至不使用从您的连接查询R以产生任何有意义的;它看起来像你可以查询 CV1 键,让您的数据:

I don't believe you should be doing a join across two data contexts. From the look of your LINQ query, you're not even using r from your join query to produce anything meaningful; it looks like you can just query cv1 and get your data:

var td = cv1.Entity_Product_Points.Where(x => x.Entity_ID == getEntity);
// Call ToList to fully enumerate the set. 

编辑:仰望的解决方案,它似乎像它可能只是作为标记每个数据上下文查询AsQueryable已获得的解决方案

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

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