c# – LINQ to SQL in而不是

前端之家收集整理的这篇文章主要介绍了c# – LINQ to SQL in而不是前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
LINQ to SQL是什么而不是平等的?

例如

  1. select * from table in ( ...)
  2. and
  3. select * from table not in (..)

LINQ to sql中的上述语句相当于什么?

解决方法

您使用,< list> .Contains(< item>)
  1. var myProducts = from p in db.Products
  2. where productList.Contains(p.ProductID)
  3. select p;

或者您可以预定义列表:

  1. var ids = {1,2,3};
  2.  
  3. var query = from item in context.items
  4. where ids.Contains( item.id )
  5. select item;

对于’NOT’的情况,只需添加’!’运算符在“包含”声明之前.

猜你在找的C#相关文章