LINQ EF和VS2017
我写了一个查询并在LINQPAD上工作LINQ EF和VS2017,linq,Linq,我写了一个查询并在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
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))
}
结果非常完美
但在visual studio中不起作用
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()的部分不起作用,因为它是linq to EF
错误:
限制必须是DbConstantExpression或Db参数引用表达式。参数名称:计数]
谢谢,祝你有愉快的一天,我不确定,但我会把它扔进去。如果您谈论的是linq to ef/sql,那么他们可能对C#一无所知。如果take()是问题所在,请尝试通过执行.tolist()首先获取select结果local。然后使用你的take函数
.ToList().Take(Tags.Count(h => h.Facility == y.FacilityID))
不确定,但我会把它扔进去。如果您谈论的是linq to ef/sql,那么他们可能对C#一无所知。如果take()是问题所在,请尝试通过执行.tolist()首先获取select结果local。然后使用你的take函数
.ToList().Take(Tags.Count(h => h.Facility == y.FacilityID))
如果你
.Take()
一个常量值,比如2?.Take()值不应该是常量,值是可变的。我的意思是,为了实验。如果在整个查询之前尝试计算Tags.Count(h=>h.Facility==y.FacilityID)
会发生什么?不幸的是,当我这样做时,该值保持不变,除了查询。有3个值在某些位置,有些位于2。所以我需要得到最后的值从每个位置。等等,但是如果您想从Where()
获取所有项目,为什么还需要.Take()
?此外,为什么LINQPad查询在.Where()
中有一个o.Facility==y.FacilityID
,而VS具有一个常量值,而不是y.FacilityID
?也许你应该把它拿回来,去掉.Take()
。如果你.Take()
是一个常量,比如2?。Take()值不应该是常量,值是可变的。我的意思是,为了实验的缘故。如果在整个查询之前尝试计算Tags.Count(h=>h.Facility==y.FacilityID)
会发生什么?不幸的是,当我这样做时,该值保持不变,除了查询。有3个值在某些位置,有些位于2。所以我需要得到最后的值从每个位置。等等,但是如果您想从Where()
获取所有项目,为什么还需要.Take()
?此外,为什么LINQPad查询在.Where()
中有一个o.Facility==y.FacilityID
,而VS具有一个常量值,而不是y.FacilityID
?也许你应该把它拿回来,然后删除.Take()
。不!work:(它给出错误=>限制必须是DbConstantExpression或DbParameterReferenceExpression。参数名称:countno!work:(它给出错误=>限制必须是DbConstantExpression或DbParameterReferenceExpression。参数名称:count