Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserManger.FindID throws an cast exception #42

Open
p10tyr opened this issue May 28, 2015 · 1 comment
Open

UserManger.FindID throws an cast exception #42

p10tyr opened this issue May 28, 2015 · 1 comment

Comments

@p10tyr
Copy link

p10tyr commented May 28, 2015

I have been trying to get a user by their ID, using UserManager, which is an email address.
For the sake of example [email protected]

I also have a Model.Person , which I store in the same database as the RavenUsers, and the Key is also the same email.

When I create the user I use this code

var user = new Models.ApplicationUser(userName); (UserName is the Email)

I have now eventually got got this working by using

var user2 = UserManager.FindByName("[email protected]");

The problem is when I use this

var user3 = UserManager.FindById("[email protected]");

I get an exception

Unable to cast object of type 'Models.Person' to type 'Models.ApplicationUser'.

I have been trying to work out what the problem is about 2 days now, on and off, but it seems when I use the FinByID, RavenDB, or Identidy.Raven DB for some reason actually matches up with the Person Key in the database. I couldn't understand why I was getting this exception the whole time since I am just calling a method and not trying to cast any thing.

When I use

var user3 = UserManager.FindByEmail("[email protected]");

It reutrns NULL, even though in the database under ApplciationUsers, the Email is the same as UserName and the same as the Key.

Is this a Identity.RavenDB problem?

@p10tyr
Copy link
Author

p10tyr commented May 28, 2015

I think I know why its getting the Person entity instead of ApplicationUser.

The entity that was returned useing FindByName, its ID is RavenUsers/[email protected]

I am a newb with RavenDB but I don't understand why the FindByID would get a result from the Persons table and then try and cast it to ApplicationUser?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant