2

このクエリをlinqで書くにはどうすればよいですか?

select * from bills as b inner join customer as c1
          On b.shipperID=c1.CustomerID inner join customer c2
          On b.ConsigneeID=c2.CustomerID      
---------------------------

以下のようにする必要があります。

var result=from p1 in entities.bills
           join p2 in entities.customer on p1.shipperID equals p2.customerID
           join p3 in entities.customer on p1.consigneeID equals p3.customerID
           select p2;
           return resuls.Tolist()

ありがとう:)

4

1 に答える 1

5

SQL ではすべてを選択しているため、linq ではすべてのオブジェクトを新しい匿名型に配置する必要があります。

var result = from p1 in entities.bills
             join p2 in entities.customer on p1.shipperID equals p2.customerID
             join p3 in entities.customer on p1.consigneeID equals p3.customerID
             select new 
                 { 
                     Bills = p1,
                     Shippers = p2,
                     Consignees = p3
                 };

             return resuls.Tolist();

または、それらを平坦化する必要がある場合は、プロパティごとに投影する必要があります。

次のような LINQ でナビゲーション プロパティを使用する必要があります。

from bills in entities.bills
select new
{
    bills.Shipper
    bills.Consignee
};
于 2013-05-28T20:13:14.810 に答える