This project is read-only.

Creating and checking users multiple times in one transaction

Topics: Troubleshooting, Writing modules
Sep 24, 2011 at 7:15 PM

Hi All,

So I am trying to do an import o fdata in to Orchard from an external file. The Import is good, but I end up with duplicate users. Here is my code

owner = _membershipService.GetUser(userName);
if (owner == null && forceCreate) {
    owner = _membershipService.CreateUser(new CreateUserParams(userName, "Password", "", string.Empty, string.Empty, true));

What happens is that if you call this twice within the same call with the same username, _membershipService.GetUser(userName); will return null everytime, and hense you endup with two users.

How can I stop this from happening?

I have tried to use a IUnitOfWorkDependency but this seems to make things worse.

Sep 24, 2011 at 7:19 PM

Ignore me!... it worked fine.... Its just the import is taking a long time. Opps!! my bad.