linq - LINQ EF 和 VS2017
问题描述
我写了一个查询并在 LINQPAD 上工作
from x in FacilityData
from y in FavInformation
where y.UserID == 1 && x.ID == y.FacilityID
select new
{
xID = x.ID,
xDistrictName = (from y in _Ilcelers
where y.ID == x.DistrictID
select y.IlceAd).FirstOrDefault(),
xName = x.Name,
Value = (from o in Tags
from p in Table_tags
where o.Prefix != null && o.Prefix == p._NAME && o.Facility == y.FacilityID
orderby p.İd descending
select new
{
FType = o.TagType,
Name = o.TagsName,
Value = p._VALUE,
Time = p._TIMESTAMP
}).Take(Tags.Count(h => h.Facility == y.FacilityID))
}
结果是完美的
但不适用于视觉工作室,
Value = (from o in DB.Tags
from p in DB.table_tags
where o.Prefix != null && o.Prefix == p.C_NAME && o.Facility == 11
orderby p.id descending
select new
{
FType=o.TagType,
Name = o.TagsName,
Value = p.C_VALUE,
Time = p.C_TIMESTAMP
}).Take(Tags.Count(h => h.Facility == y.FacilityID))
它给出了一个错误。我猜.Take()的部分不起作用,因为它是对 EF 的 linq。
错误:
Limit must be a DbConstantExpression or a Db Parameter Reference Expression. Parametre name: count]
谢谢你有美好的一天
解决方案
不确定,但我会把它扔进去。如果你在谈论 linq to ef/sql,他们可能对 C# 一无所知。如果 take() 会成为问题,请尝试通过执行 .tolist() 来首先在本地获取选择结果。然后使用您的拍摄功能。
.ToList().Take(Tags.Count(h => h.Facility == y.FacilityID))
推荐阅读
- c# - 在 Blazor 中加载一个大列表
- python - 高阶函数 Python(永无止境?)
- python - 在对多数类进行欠采样后,让训练集 < 测试集是否可行?
- ios - @Published 和 .assign 对值更新没有反应
- python - 根据每行中的数据有效地将 pandas 数据帧转换为一个热点
- ruby-on-rails - 如何在自定义类上使用 ActiveModel 的验证和回调?
- java - 在不同主机上使用 Facebook 身份验证
- python - pyTelegramBotApi 无法获取 message_id
- react-native - 如何水平和垂直渲染平面列表?
- go - 阻止来自 gorilla/mux 的打开 URL 重定向