EF多表查询方式

5, 连接

可以的连接有Join 和 GroupJoin 方法。GroupJoin组联接等效于左外部联接,它返回第一个(左侧)数据源的每个元素(即使其他数据源中没有关联元素)。

using (var edm = new NorthwindEntities())

    {

       var query = from d in edm.Order_Details

                   join order in edm.Orders

                   on d.OrderID equals order.OrderID

                   select new

                    {

                        OrderId = order.OrderID,

                        ProductId = d.ProductID,

                        UnitPrice = d.UnitPrice

                     };

        foreach (var q in query)

         Console.WriteLine("{0},{1},{2}",q.OrderId,q.ProductId,q.UnitPrice);

}

参考资料:

http://blog.csdn.net/niewq/article/details/42718515

 

posted @ 2016-06-14 14:54  jimcsharp  阅读(2987)  评论(0编辑  收藏  举报