Select records that does not exist in another table in Entity Framework

前端 未结 3 1760
情深已故
情深已故 2020-12-15 03:48

I have two tables - \"Customer\" table and \"Blacklist\" customer table. When I blacklist a customer, I put the customerid as a foreign key to Blacklist table.

What

3条回答
  •  再見小時候
    2020-12-15 04:49

    IF in table BlackList yo have a List of Customer You can perform something like

     IEnumerable model = (from c in db.Customer
                                    from b in c.BlackList.DefaultIfEmpty()
                                     where b.CusID== null
                                      select new Customer
                                       {
                                            CusId= c.OrderID
                                        }).ToList();
    

提交回复
热议问题