Reputation: 102408
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;
}
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...
If I open RavenDB Studio I can see that I have Users and Roles correctly added to the database.
This is the User data:
{
"ApplicationName": "MyApp",
"Username": "leniel",
"PasswordHash": "/L/7jv82VBSBeCDjH/gbwaKGQZGTV6na2FDiJpt6VDE=",
"PasswordSalt": "/14i7C==",
"FullName": null,
"Email": "[email protected]",
"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
}
This is the User metadata:
{
"Raven-Entity-Name": "Users",
"Raven-Clr-Type": "RavenDBMembership.User, RavenDBMembership"
}
This is how a User is created:
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?
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...
Upvotes: 1
Views: 390
Reputation: 22956
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.
EDIT:
Blah! The reason is that your documents are named "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.
Don't name your documents with Raven/ prefix, that is reserved for system documents.
Upvotes: 2