LINQ to Entities无法识别方法'Int32 Last [Int32] [英] LINQ to Entities does not recognize the method 'Int32 Last[Int32]

查看:139
本文介绍了LINQ to Entities无法识别方法'Int32 Last [Int32]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是什么问题?

int folderid = (from p in db.folder where p.isDefault == true select p.id).Last();

我收到此错误

   LINQ to Entities does not recognize the method 'Int32 Last[Int32]
    (System.Linq.IQueryable`1[System.Int32])' method, and this method cannot be 
translated into a store expression.

推荐答案

Linq无法将Last()转换为任何有效的sql语句.所以我的建议是orderby decendingTake(1)

Linq can not translate the Last() to any valid sql statment. So my suggestion would be to orderby decending and Take(1)

也许是这样的:

int? folderid =(
        from p in db.folder 
        where p.isDefault == true 
        orderby p.id descending
        select p.id
    ).Take(1).SingleOrDefault();

我不知道该选择哪一个,因此您可能必须将orderby p.id descending更改为适合您的内容.

I don't know which to take so you might have to change the orderby p.id descending to something that suites you.

这篇关于LINQ to Entities无法识别方法'Int32 Last [Int32]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆