Composite Data Service Framework 中多个Entity之间的互操作

   1: // Instantiate the DataServiceContext.
   2: context = new CompositeDataServiceSampleContainer(svcUri);
   3:
   4: // Define a LINQ query that returns Orders and Products Infomation
   5: var ordersQuery = from p in context.Products.AsEnumerable()
   6:                   from o in context.orderinfoes.AsEnumerable()
   7:                   where p.ProductID == o.ProductID
   8:                   select new
   9:                   {
  10:                       p.ProductID,
  11:                       p.Name,
  12:                       p.Price,
  13:                       o.Amount
  14:                   };
  15:
  16: this.orderItemsGrid.DataContext = ordersQuery;
其中最关键的是from p in context.Products.AsEnumerable() , 加了这个貌似就能做组合查询了,否则死也不行。。。。。

 

原始链接

http://stackoverflow.com/questions/8535960/can-we-do-cross-join-in-ef

  • You can't do joins between different data context's. You would have to do the join with linq-objects
  • uses linq-to-object cross join = it loads all data from tableA and tableB to your application and if your query contains any Where or any other clause it will be performed in your application, not in the database.
  • No entity framework query can cross boundary of single context. So cross join is supported as @Aducci showed in his response but cross context or cross database linq-to-entities queries are not supported.  

因此总的来说,要使用这个,必须要用Composite Data Service Framework 将多个数据源集成进一个数据源,即一个context才能用,否则一切都是白搭。