RavenDB LINQ查询不再与新的稳定版本一起使用(#616) [英] RavenDB LINQ Query no longer works with new stable build (#616)
问题描述
我正在使用 RavenDBMembership 提供程序,并尝试使用最新的
I'm using RavenDBMembership Provider and after trying the latest RavenDB new stable build (#616) one LINQ query simply stopped working. This is the method:
private MembershipUserCollection FindUsers(
Func<User, bool> predicate, int pageIndex, int pageSize, out int totalRecords)
{
var membershipUsers = new MembershipUserCollection();
using (var session = DocumentStore.OpenSession())
{
var q = from u in session.Query<User>()
where u.ApplicationName == ApplicationName //ApplicationName="MyApp"
select u;
IEnumerable<User> results;
if (predicate != null)
{
results = q.Where(predicate);
}
else
{
results = q;
}
totalRecords = results.Count(); // Returns 0 but I do have 2 Users in the DB.
// I also tried executing the query directly:
// totalRecords = q.Count(); // Returns 0 but I do have 2 Users in the DB.
var pagedUsers = results.Skip(pageIndex * pageSize).Take(pageSize);
foreach (var user in pagedUsers)
{
membershipUsers.Add(UserToMembershipUser(user));
}
}
return membershipUsers;
}
上面的LINQ查询使用我正在使用的RavenDB的先前版本(#573)正确返回用户.为了测试这一点,我删除了NuGet软件包(#616)并安装了旧的软件包(#573),该查询才有效...
That LINQ query above returns the Users correctly with the previous version of RavenDB I was using (#573). To test this, I removed the NuGet package (#616) and installed the old one (#573) and the query just works...
如果我打开RavenDB Studio,则可以看到我已将用户和角色正确添加到数据库中.
If I open RavenDB Studio I can see that I have Users and Roles correctly added to the database.
这是用户数据:
{
"ApplicationName": "MyApp",
"Username": "leniel",
"PasswordHash": "/L/7jv82VBSBeCDjH/gbwaKGQZGTV6na2FDiJpt6VDE=",
"PasswordSalt": "/14i7C==",
"FullName": null,
"Email": "leniel@gmail.com",
"DateCreated": "2012-02-02T05:02:22.0615234",
"DateLastLogin": null,
"Roles": [],
"PasswordQuestion": null,
"PasswordAnswer": null,
"IsLockedOut": false,
"IsOnline": false,
"FailedPasswordAttempts": 0,
"FailedPasswordAnswerAttempts": 0,
"LastFailedPasswordAttempt": "0001-01-01T00:00:00.0000000",
"Comment": null,
"IsApproved": true
}
这是用户元数据:
{
"Raven-Entity-Name": "Users",
"Raven-Clr-Type": "RavenDBMembership.User, RavenDBMembership"
}
这是创建用户的方式:
public User()
{
Roles = new List<string>();
Id = "raven/authorization/users/"; // db assigns id
}
我阅读了最新的构建页面,但找不到原因.有我不知道的重大变化吗?
I read the latest build page but couldn't find a reason for this. Is there any breaking change that I'm unaware of?
现在我必须在这个特定的MembershipProvider项目中坚持稳定的内部版本#573,因为我不知道RavenDB内部的情况是什么.
For now I have to stick with stable build #573 in this specific MembershipProvider project since I don't have a clue about what's going on in the internals of RavenDB...
推荐答案
问题是这样的:Func<User, bool> predicate
您将其传递给Query.在这里,您实际上是在内存中进行评估.
您需要使用Expression<Func<User, bool>>
使其实际上是可以作为查询处理的linq语句.
The problem is this: Func<User, bool> predicate
You are passing it to the Query.Where, you are actually doing the evaluation in memory.
You need to use Expression<Func<User, bool>>
for it to actually be a linq statement that can be processed as a query.
如果不是这种情况,我们将感谢失败的测试用例.
If this isn't the case, we would appreciate a failing test case.
布拉! 原因是您的文档被命名为"raven/..."
Blah! The reason is that your documents are named "raven/..."
前缀为Raven/的文档未编入索引.
And documents prefixed with Raven/ are NOT indexed.
之前,我们为此进行了区分大小写的匹配,现在我们进行了不区分大小写的匹配.
Before, we did a case sensitive match for that, now we do a case insensitive match.
不要用Raven/前缀命名您的文档,该前缀是系统文档专用的.
Don't name your documents with Raven/ prefix, that is reserved for system documents.
这篇关于RavenDB LINQ查询不再与新的稳定版本一起使用(#616)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!