LINQ EF和VS2017

时间:2019-02-26 12:48:38

标签: 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
                     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))
}

result

结果完美

但不适用于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() 的部分不起作用,因为它对EF不利。

错误:

  

Limit must be a DbConstantExpression or a Db Parameter Reference Expression. Parametre name: count]

error image

谢谢你的美好的一天

1 个答案:

答案 0 :(得分:0)

不确定,但是我只是将它扔进去。如果您正在谈论linq to ef / sql,那么他们可能对C#一无所知。如果take()成为问题,请尝试通过执行.tolist()首先将选择结果获取到本地。然后使用您的功能。

Parse.enableLocalDatastore(this);
   Parse.initialize(new Parse.Configuration.Builder(this.getApplicationContext())
                    .applicationId(MyapplicationID)
                    .clientKey(clientk)
                    .server(ServerURL)
                    .enableLocalDataStore()
                    .build()        );