【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;
        }请问这个问题怎么解决?

解决方案 »

  1.   

    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();语法不对!!
      

  2.   

    result = (from m in context.Moni_StockACC where m.UserInfoId == userid
      join n in context2.StockA_HangQing
      on m.Code equls n.StockSymbol
      select (decimal.Parse(n.Price.ToString()) - m.Price) * m.Count).Sum();
      

  3.   

    from m in context.Moni_StockACC where m.UserInfoId == userid
      from n in context2.StockA_HangQing
    m  n join一下
      

  4.   

    context = new DataBase.Model.AccountInfoDataContext();
    context2 = new DataBase.Model.HangQingInfoDataContext();//里面是另外一个数据库的视图
    断点调试下,看看这两个context是否取到值
      

  5.   

    上面的语句我也写错啦,对不起:result = 
    (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();