解决方案 »

  1.   

    linq 里面直接用 
    var q =
        from c in db.Customers
        from o in c.Orders
        where c.City == "London"
        select o;代替joinhttp://www.cnblogs.com/Mayvar/archive/2011/07/04/wanghonghua_20110704.html
      

  2.   

       select new
                             {
                                c.Customer,
                                item.Product,
                                item.Quantity,
                                item.Price,
                                item.Amount,
                             }.ToString();
    为什么要ToString()?
      

  3.   

    试一试:
    var query = from c in ctx.ClearingRecord
                join item in ctx.ClearingRecordItem on c.Id equals item.ClearingRecordId
                where c.ClearingDate  >= dateBegin && c.ClearingDate<= dateEnd
                select new
                            {
                               c.Customer,
                               item.Product,
                               item.Quantity,
                               item.Price,
                               item.Amount,
                            }
                                    我的多表查询的代码,没有问题啊:var query = from oi in context.OrderItems
                                join o in context.Orders on oi.OrderId equals o.OrderId
                                join p in context.Products on oi.ProductId equals p.ProductId
                                where p.ProductId == 310  
                                select o;
           
      

  4.   

    去掉红色部分看看
    select new
                            {
                               c.Customer,
                               item.Product,
                               item.Quantity,
                               item.Price,
                               item.Amount,
                            }.ToString();
      

  5.   

     SQL  用的 FramworkEntity 模型搞的
      

  6.   

    还是没用,估计是返回值问题, 因为是多表查询 我返回值是做的一个 类 public class ProductListModel
        {
            
            public string Product { get; set; }
            public string Quantity { get; set; }
            public string Price { get; set; }
            public string Amount { get; set; }
        }
      

  7.   

    public List< ProductListModel> GetProductList( DateTime dateBegin, DateTime dateEnd ,String productName)
            {
                dateBegin = DateTime.Parse(dateBegin.ToString("yyyy-MM-dd 00:00:00"));
    dateEnd = DateTime.Parse(dateEnd.ToString("yyyy-MM-dd 23:59:59"));
                var query = (from clist in ctx.ClearingRecord  where (clist.ClearingDate >= dateBegin && clist.ClearingDate<= dateEnd) select clist ).ToList();
               return   ( from c in query  join item in ctx.ClearingRecordItem
                            on  c.Id equals item.ClearingRecordId
                            select new
                            {
                               c.Customer,
                               item.Product,
                               item.Quantity,
                               item.Price,
                               item.Amount,
                            }ToList();
            }
      

  8.   

    对于Linq的Join问题,可以试试Linq之外的方式,比如使用OQL,可以使用如下的方式,它更接近于SQL:ClearingRecord c=new ClearingRecord();
    c.CustomerName="XX Name";
    c.ClearingDate=DateTime.Now.AddYear(-1);ClearingItem i=new ClearingItem ();OQL q=OQL.From(c)
             .InnerJoin(i).On(c.id,i.ClearingRecordId)
             .Select(c.id,c.CustomerName,c.ClearingDate,i.Amount,i.Price)
             .Where(c.CustomerName,c.ClearingDate)
             .End;
     
    //db is AdoHelper
    EntityContainer ec = new EntityContainer(q, db);
    var mapEntity=ec.Map<ResultClass>((e)=>
    {
      e.id=ec.GetItemValue<int>(0);
      e.CustomerName=ec.GetItemValue<string>(1);
      e.ClearingDate=ec.GetItemValue<DateTime>(2);
      e.Amount=ec.GetItemValue<int>(3);
      e.Price=ec.GetItemValue<Decimal>(4);
      return e;
    }
    ).ToList();详细信息可以参考这篇文章《打造轻量级的实体类数据容器
      

  9.   

    LINQ TO SQL 肯定支持join啥var query = from c in
                 (from clist in ctx.ClearingRecord  
                  where (clist.ClearingDate >= dateBegin && clist.ClearingDate<= dateEnd)
                                            select clist
                                            )
                            join item in ctx.ClearingRecordItem
                            on  c.Id equals item.ClearingRecordId
                            select new
                            {
                               c.Customer,
                               item.Product,
                               item.Quantity,
                               item.Price,
                               item.Amount,
                            }
      

  10.   

    参考http://www.cnblogs.com/Mayvar/archive/2011/07/04/wanghonghua_20110704.html
      

  11.   

    我跟你一样,找了半天就找到你和我差不多
                var staffs = from s in staff.Staffs
                             join d in staff.Departments
                             on s.staff_depNumber equals d.dep_number
                             where s.staff_id == 1
                             select new
                             {
                                s,d
                             };
    一开始我是这样的 提示:不支持方法join;
    后来妈的把我惹火了,我就这样了;\
                var staffs = from s in staff.Staffs.ToList()
                             join d in staff.Departments.ToList()
                             on s.staff_depNumber equals d.dep_number
                             where s.staff_id == 1
                             select new
                             {
                                s,d
                             };
    草你妈的 居然成功了。
    然后我删除了 第一个ToList() 失败了 还是提示不支持方法 join;
    然后我加上一个ToList()删除第二个ToList()也成功了成功了。
    数据库字段类型只有int datetime nvarchar(n) 求大神给个解释。
      

  12.   

    因为join方法第一个参数必须是IEnumerable类型的,也就是必须是本地数据因为join方法第一个参数必须是IEnumerable类型的,也就是必须是本地数据,针对你们两个的问题可以把join之前那个数据源转化为本地数据既用asEnumerable方法或tolist方法之后就不会出现这个错误了