I'm trying to find a member on my website using the MemberService.
When I use the following query :
var umbracoMember = ApplicationContext.Current.Services.MemberService
.FindByUsername(username, 1, 10, out totalRecords, Umbraco.Core.Persistence.Querying.StringPropertyMatchType.Exact)
.FirstOrDefault();
umbracoMember ends up being null. However, in the same function if I use the old API to find the member :
var oldApiMember = umbraco.cms.businesslogic.member.Member.GetMemberByName(username, true);
oldApiMember is not null (and contains my member).
When I look at the backend I see the member I am searching for :
Both the name and username are the same string, and I compared it to the "username" variable I use in my function, both are the same.
What's going on? Why won't the service find it? My member belongs to the default member type "Member". I don't use Member Groups right now but added one just to test and made my member a part of it (it didn't change anything).
actually works as expected. I'll go with that but i'm still very curious as to what's going on with the first code I posted (which seems like it should work). There must be a distinction I don't understand between the two methods?
I have just been wrestling with this problem. In my case I had a leftover leading whitespace. Very hard to spot unless you copy and paste a good example and a bad example and compare.
For anybody looking at this in the future, could it be that you're looking at index 1 instead of 0, so you're telling it to find the second page of results (which will be empty)? i.e. it should be:
var umbracoMember = ApplicationContext.Current.Services.MemberService
.FindByUsername(username, 0, 10, out totalRecords, Umbraco.Core.Persistence.Querying.StringPropertyMatchType.Exact)
.FirstOrDefault();
MemberService FindByUsername not working?
Hi All,
I'm trying to find a member on my website using the MemberService.
When I use the following query :
umbracoMember ends up being null. However, in the same function if I use the old API to find the member :
oldApiMember is not null (and contains my member).
When I look at the backend I see the member I am searching for :
Both the name and username are the same string, and I compared it to the "username" variable I use in my function, both are the same.
What's going on? Why won't the service find it? My member belongs to the default member type "Member". I don't use Member Groups right now but added one just to test and made my member a part of it (it didn't change anything).
Anyone has a clue where I should look?
Thanks!
Kept digging around for this to work and trying with
actually works as expected. I'll go with that but i'm still very curious as to what's going on with the first code I posted (which seems like it should work). There must be a distinction I don't understand between the two methods?
Thanks!
@AmandaEly : And what about if with the code I posted in my second post :
Does that work?
I have just been wrestling with this problem. In my case I had a leftover leading whitespace. Very hard to spot unless you copy and paste a good example and a bad example and compare.
For anybody looking at this in the future, could it be that you're looking at index 1 instead of 0, so you're telling it to find the second page of results (which will be empty)? i.e. it should be:
I'm running Umbraco 7.4.3 and can't get this to work. I'm using
but always get result null. Anyone who wknows where to start looking?
I've had exactly this, working in 7.2.8.. Didn't touch the code, but in 7.12.1 it always returns null. Not sure what alternative to use?
Could you get this to work? Or anyone else?
is working on a reply...