0

我有三个表,我需要使用 C# 对 LINQ 执行内部联接查询。我可以半途而废,但我是初学者,非常需要帮助

SQL 查询

Select O.CarID, C.customerID, C.Name, C.Address, V.Brand, V.Model, V.Model_Year 
FROM Car_OwnerShip As O, Customers As C, Cars As V
WHERE V.CarID = O.CarID AND O.customerID = C.customerID AND C.Name='toxic';

在此处输入图像描述

4

3 回答 3

5

我认为这样的事情可以解决问题:

Car_Ownership
.Join
(
    Customers,
    o=>o.customerID,
    c=>c.customerID,
    (o,c)=>new{o,c}
)
.Join
(
    Cars,
    o=>o.o.CarId,
    v=>v.CarID,
    (o,v)=>new{o,v}
)
.Where
(
    x=>
    x.o.c.Name == "toxic"
)
.Select
(
    x=>
    new
    {
        CarID = x.o.o.CarID,
        customerID = x.o.c.customerID,
        Name = x.o.c.Name,
        Address = x.o.c.Address,
        Brand = x.v.Brand,
        Model = x.v.Model,
        Model_Year = x.v.Model_Year
    }
)
于 2013-08-05T09:21:39.057 回答
2
var query = from owner in Car_OwnerShip
            from customer in Customers
            from car in Cars 
            select new { owner, customer, car }
            where owner.CarID = car.CarID and owner.CustomerID = customer.CustomerId and customer.Name = "toxic";
于 2013-08-05T09:24:55.117 回答
2

尝试这个

from o in Car_OwnerShip
join c in Customers on o.customerID equals c.customerID
join v in Cars on o.CarID equals v.CarID 
where c.Name=='toxic'
select new {
O.CarID, C.customerID, C.Name, C.Address, V.Brand, V.Model, V.Model_Year 
}
于 2013-08-05T09:25:24.477 回答