0

I've searched to a help for connection between own models and the existing authorization models in Code First. But have nothing found what helped to me. (For example, trying this). My exact problem: I have a model with the entity added_from or last_edited_from and want to set a reference to the user-id. I tried it in some different ways.

The most logical way for me was:

public class aTable
{
        [...]
        [ForeignKey("last_edited_from")]
        public ApplicationUser userFK { get; set; }
        public string last_edited_from { get; set; }
}

But when I tried this I got the following error in the Package Manager console (after "add-migration")

MyProj.DAL.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType.
MyProj.DAL.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType.
IdentityUserLogins: EntityType: EntitySet 'IdentityUserLogins' is based on type 'IdentityUserLogin' that has no keys defined.
IdentityUserRoles: EntityType: EntitySet 'IdentityUserRoles' is based on type 'IdentityUserRole' that has no keys defined.
Soheil Alizadeh
  • 2,936
  • 11
  • 29
  • 56
Blacky.17
  • 25
  • 5
  • please edit your ask and add user model – Soheil Alizadeh Jan 09 '17 at 08:59
  • have you marked `[Key]` for identity property in your entity class, @Blacky.17? – Bob Dust Jan 09 '17 at 09:00
  • Your error indicates that you use Identity 2.0 so for This Issue is need share your identity code for get better answer – Soheil Alizadeh Jan 09 '17 at 09:11
  • I'll use the Microsoft.AspNet.Identity, there's no own identity code – Blacky.17 Jan 09 '17 at 09:15
  • @blacky.17 you not defind Key in User Model That inheritance of `IdentityUser` – Soheil Alizadeh Jan 09 '17 at 09:56
  • I got the solve of my problem, the `IdentityUser` was set to the `DefaultConnection`-String. I have set it to my own Connection-String, have let my UserTable inherit from `IdentityUser` and replaced `public ApplicationUser userFK { get; set; }` with `public User userFK { get; set; }` – Blacky.17 Jan 09 '17 at 16:22
  • Possible duplicate of [EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType](http://stackoverflow.com/questions/28531201/entitytype-identityuserlogin-has-no-key-defined-define-the-key-for-this-entit) – trailmax Jan 11 '17 at 23:21
  • Or this http://stackoverflow.com/a/19916771/809357 – trailmax Jan 11 '17 at 23:21
  • And this: http://stackoverflow.com/a/19995982/809357 – trailmax Jan 11 '17 at 23:21

0 Answers0