方法X还没有支持转换为SQL [英] Method x has no supported translation to SQL
本文介绍了方法X还没有支持转换为SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写这应该得到一个用户对象和消息的用户已经发布量的查询。我这样做以下方式:
I want to write a query which should get an user object and the amount of messages the user has posted already. I did this the following way:
var query = (from u in _db.Repository<User>()
where u.IsDeleted != true
select new UserWithMessagecount()
{
User = u
MessageCount = GetUserMessageCount(u.Documents).Count(),
});
我使用的方法,因为一些消息应该被过滤掉(在一个动态的方式)
为了简单起见,我会发布功能,无需排序逻辑(这仍然产生相同的错误)。
To keep things simple I'll post the function without sorting logic (which still produces the same error).
private EntitySet<Document> GetUserMessageCount(EntitySet<Document> set)
{
return set;
}
返回的错误是:
The error returned is:
方法'X'没有支持转换为SQL。
Method 'x' has no supported translation to SQL.
在如何解决这个问题的任何想法?
Any ideas on how to fix this issue?
推荐答案
使用语法来代替:
var query = (from u in _db.Repository<User>()
let MessageCount = GetUserMessageCount(u.Documents).Count()
where u.IsDeleted != true
select new UserWithMessagecount()
{
User = u,
MessageCount = MessageCount
});
这篇关于方法X还没有支持转换为SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文