【发布时间】:2012-05-13 13:53:00
【问题描述】:
这是我的查询:
var x = db
.Users
.Where(u => u.Locations.Any(l => searchedLocation.Counties.Any(c => c.LocationId == l.LocationId));
上下文:
-
Users是IQueryable<User>。 (EF 对象集) -
searchedLocation是一个Location对象。 -
Counties是ICollection<MiniLocation>。
我想要做什么:
返回所有用户,其中这些位置的任何县都具有属于搜索位置的任何县的 locationId。
示例:
搜索纽约市 (LocationId = 1. County1LocationId = 2)
用户:鲍勃。地点:苏活区。 County1LocationId = 2。County2 LocationId = 3。
所以这是一场比赛。 (因为 Soho 有一个 LocationId 为 2 的县,NYC 也是如此)
我收到错误:
无法创建“xxx.xxx.Locations.MiniLocation”类型的常量值。此上下文仅支持原始类型(“例如 Int32、String 和 Guid”)。
有什么想法吗?
【问题讨论】:
标签: c# linq entity-framework