在带有 Nhibernate 的 Linq 中使用 Count() 时不支持指定的方法

Specified method is not supported when using Count() in Linq with Nhibernate

当我使用 .Count() 时出现此错误:

the specified method not supported

在这一行我收到类似 Sql not found:

的错误
session.Query<Table>().Select(x => new { x.Id }).Distinct();

这是完整代码:

var List = session.Query<Table>().Select(x => new { x.Id }).Distinct();
foreach (var id in SelectedIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
    var count = List.Where(x => x.Id == Int32.Parse(id)).Count();
    if (count > 0)
    {

    }
}

是 Nhibernate 有问题还是我遗漏了什么?

尝试像这样放演员表:

int idCompare = Int32.Parse(id);
var count = List.Where(x => x.Id == idCompare).Count();

Linq 无法将每个 .NET Framework 高级函数转换为 sql。

也许这可以解决您的问题。

当您需要检查 .NET 方法在 linq 中是否可用时,您可能需要检查 this source and also this