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.

9
  • please edit your ask and add user model Commented Jan 9, 2017 at 8:59
  • have you marked [Key] for identity property in your entity class, @Blacky.17? Commented Jan 9, 2017 at 9:00
  • Your error indicates that you use Identity 2.0 so for This Issue is need share your identity code for get better answer Commented Jan 9, 2017 at 9:11
  • I'll use the Microsoft.AspNet.Identity, there's no own identity code Commented Jan 9, 2017 at 9:15
  • @blacky.17 you not defind Key in User Model That inheritance of IdentityUser<Tkey,...> Commented Jan 9, 2017 at 9:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.