gpt4 book ai didi

c# - Entity Framework .Any() 过滤器出错

转载 作者:太空狗 更新时间:2023-10-29 23:47:27 24 4
gpt4 key购买 nike

这是我的查询:

var x = db
.Users
.Where(u => u.Locations.Any(l => searchedLocation.Counties.Any(c => c.LocationId == l.LocationId));

上下文:

  • UsersIQueryable<User> . (EF 对象集)
  • searchedLocationLocation对象。
  • CountiesICollection<MiniLocation> .

我正在尝试做的事情:

Return all users, where any of the Counties for those locations have a locationId of any of the counties belonging to the searched location.

示例:

搜索纽约市(LocationId = 1. County1LocationId = 2)

用户:鲍勃。地点:Soho。 County1LocationId = 2. County2 LocationId = 3.

所以这是一场比赛。 (因为 Soho 有一个 LocationId 为 2 的县,纽约市也是)

我收到的错误:

Unable to create a constant value of type 'xxx.xxx.Locations.MiniLocation'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.

有什么想法吗?

最佳答案

MSDN page声明不支持此构造。您可以使用 this method .Net 3.5 Linq to Entities 帮助替换 Any 的使用。

关于c# - Entity Framework .Any() 过滤器出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10441720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com