James Reategui
James Reategui

Reputation: 1347

asp net Identity 2.0 beta1 with extended Guid Primary Key EF Migrations issue

I'm using ASP Net Identity 2.0 beta1 and followed the instructions on: http://blogs.msdn.com/b/webdev/archive/2013/12/20/announcing-preview-of-microsoft-aspnet-identity-2-0-0-alpha1.aspx to extend the Primary Key to be a GUID instead of the standard string. I had to do this for foreign keys to work with existing tables. Using Code First.

I do not have any extra code in my db context OnModelCreating.

The issue I'm having, is when trying to Add-Migration I get the error:

MyApp.Business.GuidUserLogin: : EntityType 'GuidUserLogin' has no key defined. Define the key for this EntityType.

MyApp.Business.GuidUserRole: : EntityType 'GuidUserRole' has no key defined. Define the key for this EntityType.

GuidUserLogins: EntityType: EntitySet 'GuidUserLogins' is based on type 'GuidUserLogin' that has no keys defined.

GuidUserRoles: EntityType: EntitySet 'GuidUserRoles' is based on type 'GuidUserRole' that has no keys defined.

Upvotes: 0

Views: 356

Answers (1)

James Reategui
James Reategui

Reputation: 1347

The fix was to manually add the keys in the DbContext under the OnModelCreating override:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{   
        modelBuilder.Entity<GuidUserRole>().HasKey( x=> new {
            x.RoleId,
            x.UserId
        });

        modelBuilder.Entity<GuidUserLogin>().HasKey(x => new
        {
            x.UserId,
            x.ProviderKey,
            x.LoginProvider
        });
}

After this addition the ef migrations worked fine and I was able to create users roles etc.

Upvotes: 1

Related Questions