2016-09-26 66 views
-2

這是查詢:如何將這個SQL查詢寫入LINQ?

select * from Product 
    inner join Restaurant on Product.RestaurantId=Restaurant.RestaurantId 
    where Product.ProductName like '%something%' and Restaurant.RestaurantAddress 
    like '%something%' 
+1

搜索如何加入使用LINQ名單... –

回答

0

您可以按以下:

var result = (from p in db.Product 
       join r in db.Restaurant on p.RestaurantId equals r.RestaurantId 
       where 
        p.ProductName.Contains("something") && 
        r.RestaurantAddress.Contains("something") 
       select new 
       { 
        Product = p, 
        Restaurant = r 
       }).ToList();