【Linq】查询包含对不同数据上下文上所定义项的引用?? public static decimal GetStockAFloatYingKui(int userid)
{
DataBase.Model.AccountInfoDataContext context = null;
DataBase.Model.HangQingInfoDataContext context2=null;
decimal result = 0;
try
{
context = new DataBase.Model.AccountInfoDataContext();
context2 = new DataBase.Model.HangQingInfoDataContext();//里面是另外一个数据库的视图
result = (from m in context.Moni_StockACC where m.UserInfoId == userid
from n in context2.StockA_HangQing
where m.Code == n.StockSymbol
select (decimal.Parse(n.Price.ToString()) - m.Price) * m.Count).Sum();
// result = decimal.Parse((from n in context2.StockA_HangQing select n.Price).Max().ToString());
}
catch
{
}
finally
{
if(context!=null)
{
context.Dispose();
}
}
return result;
}请问这个问题怎么解决?
{
DataBase.Model.AccountInfoDataContext context = null;
DataBase.Model.HangQingInfoDataContext context2=null;
decimal result = 0;
try
{
context = new DataBase.Model.AccountInfoDataContext();
context2 = new DataBase.Model.HangQingInfoDataContext();//里面是另外一个数据库的视图
result = (from m in context.Moni_StockACC where m.UserInfoId == userid
from n in context2.StockA_HangQing
where m.Code == n.StockSymbol
select (decimal.Parse(n.Price.ToString()) - m.Price) * m.Count).Sum();
// result = decimal.Parse((from n in context2.StockA_HangQing select n.Price).Max().ToString());
}
catch
{
}
finally
{
if(context!=null)
{
context.Dispose();
}
}
return result;
}请问这个问题怎么解决?
from n in context2.StockA_HangQing
where m.Code == n.StockSymbol
select (decimal.Parse(n.Price.ToString()) - m.Price) * m.Count).Sum();语法不对!!
join n in context2.StockA_HangQing
on m.Code equls n.StockSymbol
select (decimal.Parse(n.Price.ToString()) - m.Price) * m.Count).Sum();
from n in context2.StockA_HangQing
m n join一下
context2 = new DataBase.Model.HangQingInfoDataContext();//里面是另外一个数据库的视图
断点调试下,看看这两个context是否取到值
(from m in tmp1
join n in tmp2
on m.Code equls n.StockSymbol
where m.UserInfoId == userid
select (decimal.Parse(n.Price.ToString()) - m.Price) * m.Count).Sum();