Retrieve user right after it was created = null?

Topics: General, Writing modules
May 13, 2013 at 7:56 AM
Hi,

I'm writing a custom module for user registration. Most of the profile data is saved in our backoffice, but the password/email is saved in Orchard.

Somewhere in the code is this line:
var user = membershipService.CreateUser(new CreateUserParams(saveClientResponse.ClientId.ToString(), member.Password, member.Email, null, null, false));
Later in the code, I try to get the inserted user:
var test = membershipService.GetUser(saveClientResponse.ClientId.ToString());
However, test == null when this line is executed in the same http request as CreateUser(). During the next http request, I can retrieve the user without problems.

What happens? Is this NHibernate? Does it only write to the database at the end of the request?
May 13, 2013 at 1:37 PM
I think you have to execute the flush command with the contentmanagement service
May 15, 2013 at 8:39 AM
Ah, yes... according to the docs this is exactly what I need!

Thanks once again, Znowman!
Developer
May 15, 2013 at 8:40 AM
Also note that Flush() will be removed with 1.7 (is already removed from the latest source) because autoflushing will work. Thus don't be surprised when your module breaks with 1.7: just remove the Flush() call.
May 15, 2013 at 9:14 AM
Good to know.

What does autoflush actually do? Flush modifications on content items immediately to the database? Or is it smart enough to see I'm trying to query something that's not yet flushed?
Developer
May 15, 2013 at 9:26 AM
I don't know the details, sorry, but it should work exactly like NHibernate's built-in autoflushing.
May 15, 2013 at 7:54 PM
Piedone wrote:
Also note that Flush() will be removed with 1.7 (is already removed from the latest source) because autoflushing will work. Thus don't be surprised when your module breaks with 1.7: just remove the Flush() call.
Would it be more prudent to decorate it as obsolete and notify as a warning - basically not doing anything harmful rather than potentially letting the modules fail as well as several from the gallery? Then again people should test before an update, but choosing modules online will be a little more work if the core continues to mutate even when it is for the better.