Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数据库中存在的不包含';名单上没有_C#_Linq To Entities - Fatal编程技术网

C# 数据库中存在的不包含';名单上没有

C# 数据库中存在的不包含';名单上没有,c#,linq-to-entities,C#,Linq To Entities,我在数据库表中有带记录的礼品,例如: Id: 1, Name: A Id: 2, Name: B Id: 3, Name: C Id: 1, Name: A_update Id: 3, Name: C_update Id: 0, Name: D_new 在IEnumerable gifts中,我有用户修改后提供的元素,例如: Id: 1, Name: A Id: 2, Name: B Id: 3, Name: C Id: 1, Name: A_update Id: 3, Name: C_u

我在数据库表中有带记录的礼品,例如:

Id: 1, Name: A
Id: 2, Name: B
Id: 3, Name: C
Id: 1, Name: A_update
Id: 3, Name: C_update
Id: 0, Name: D_new
IEnumerable gifts
中,我有用户修改后提供的元素,例如:

Id: 1, Name: A
Id: 2, Name: B
Id: 3, Name: C
Id: 1, Name: A_update
Id: 3, Name: C_update
Id: 0, Name: D_new
现在,我希望数据库中存在的记录在列表中不存在-因此在本例中,它应该是一条记录:

Id: 2, Name: B
因为下面的代码不起作用,我该怎么做:

List<Gifts> result = db.Gifts.Where(x => !gifts.Select(y => y.Id).Contains(x.Id)).ToList();
List result=db.Gifts.Where(x=>!Gifts.Select(y=>y.Id).Contains(x.Id)).ToList();
无法创建“MyProject.Models.Gift”类型的常量值。 此类型中仅支持基元类型或枚举类型 上下文


这是实体框架的一个局限性。In仅支持在表达式中使用某些特定的数据类型

如果使用Entity Framework 4.0或更高版本,则可以使用以下解决方法:

int[] giftIds = gifts.Select(y => y.Id);
List<Gifts> result = db.Gifts.Where(x => !giftIds.Contains(x.Id)).ToList();
int[]giftIds=gifties.Select(y=>y.Id);
List result=db.gives.Where(x=>!giftIds.Contains(x.Id)).ToList();