开发者

The query contains references to items defined on a different data context

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();

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!


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. 

EDIT: Looking up a solution, it seems like it might be just as easy as marking each data context query AsQueryable to get the solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜