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!
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0