如何使用LINQ选择不在外键表中的记录?

时间:2016-05-07 08:33:57

标签: c# linq-to-sql

我有以下实体

1. tbl_city

    City_id pk AI

    City_name    

2. tbl_area

    area_id pk

    area_name

    city_id fk tbl_city(city_id)

3. tbl_restaurant

   restaurant_id pk 

   restaurant_name


4. tbl_restaurant_areas

   restaurant_area_id pk

   area_id fk tbl_area(area_id)

   restaurant_id fk tbl_restaurant(restauran_id)

现在我有一个接受两个参数city_idrestaurant_id的方法,它们应该从tbl_area中选择tbl_restaurant_areas中不存在的区域from a in ctx.tbl_areas where a.city_id==city_id && !ctx.tbl_restaurant_areas .Any(ra => (ra.area_id==a.area_id) && ra.reastaurant_id==restaurant_id) select new {a}; 。我的LINQ查询如下所示

var myObject = {
    name: "Peter Foti",
    'course': 'JavaScript',
    grade: 'A', 
    level: 3
};

0 个答案:

没有答案