我在 Stackoverflow 上阅读了其他几篇文章,但我的问题很简单且不同。我有 2 个独立的数据库,这就是为什么我有两个独立的 Datacontext。这是我的查询,我在其中传递参数并将其绑定到我的 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 个数据库的表中添加一条记录时,我做了同样的事情。它正在插入行,但也引发相同的错误。周围的情况怎么样?谢谢你!
我不认为您应该跨两个数据上下文进行连接。从 LINQ 查询的外观来看,您甚至没有使用连接查询中的 r 来生成任何有意义的内容;看起来你可以直接查询cv1
并获取您的数据:
var td = cv1.Entity_Product_Points.Where(x => x.Entity_ID == getEntity);
// Call ToList to fully enumerate the set.
编辑:查找解决方案,看起来可能就像将每个数据上下文查询标记为 AsQueryable 一样简单以获取solution.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)