2

I have an asp.net mvc project that uses asp.net Identity to authenticate users. The database has been designed in entity framework designer.

There is a table named "Farmers" and I want to allow each farmer to login to the application. As I know in order to achieve this, the farmer must inherit from IdentityUser, but how can I do this in entity framework designer?

Manos Pasgiannis
  • 1,693
  • 1
  • 18
  • 30
  • `IdentityUser` is abstract. You need to inherit from *your* user (`ApplicationUser` if you left the default project template intact). – Chris Pratt Aug 22 '14 at 21:38
  • I can suggest not to mix objects and have `IdentityUser` separate from your `Farmer` and have 1-1 link between the tables. Users are more application concept, farmers are domain objects. Two are linked, but not the same. – trailmax Aug 22 '14 at 22:08
  • @ChrisPratt I can't inherit from ApplicationUser because ApplicationUser doesn't exist in the edmx that I have the Farmer entity. Is there a way to move Application user in this edmx? – Manos Pasgiannis Aug 23 '14 at 09:44

3 Answers3

0

what is your mvc version??

in mvc5 this is a good response

http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx

for this way u can mixed the two tables.

the other way is create an relationship between the two tables an use

User.Identity.Name or

User.Identity.GetHashCode

an use this to obtain the values of connected user

chefjuanpi
  • 1,570
  • 15
  • 27
  • It would be best to have some of the linked content quoted in your answer, in case the link goes bad in the future. – Air Aug 22 '14 at 23:30
0

After a lot of hours of research I figured out that inherit from ApplicationUser or IdentityUser is not possible using the Entity Framework Designer.

My solution is to create a Code First Model from the existing database and then inherit from ApplicationUser.

Manos Pasgiannis
  • 1,693
  • 1
  • 18
  • 30
0

As far as I know you can't really do that and I would argue that you shouldn't even try to do that even if you could.

By inheriting from IdentityUser you are saying that the Farmer can be described by properties like SecurityStamp, Roles or PasswordHash (inherited from IdentityUser) which does not make that much sense from a design point of view.

If what you are looking for is having a direct association between a user and a farmer you could simply add a required UserId property in you Farmer model. So whenever you create a new UserIdentity instance you also create a new Farmer instance as well with the UserId set to be the Id property of the newly created UserIdentity.