4

I am struggling to add a few fields to the standard ApplicationUser object with the code below. I have successfully run Migrations and i can see the database scheme is updated with the new fields in the database. I followed the tutorial at http://go.microsoft.com/fwlink/?LinkID=317594

public class ApplicationUser : User
{

    public string LegacyPassword { get; set; }
    public DateTime DateCreated { get; set; }
    public bool Activated { get; set; }

}

The problem i experience is now when i try execute registration such as :

 var u = new Test.Models.ApplicationUser() { UserName = userName, DateCreated = System.DateTime.Now, PassHash = "" };
            IdentityResult result = manager.Users.CreateLocalUser(u, Password.Text);

I get the following error when CreateLocalUser() executes...:

An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code

Additional information: Mapping and metadata information could not be found for EntityType 'Test.Models.ApplicationUser'.

I have tried recreating the migrations about 5/6 times and started a brand new project as well but i cannot get past this error.

Any ideas?

Piotr Stulinski
  • 9,241
  • 8
  • 31
  • 46
  • I think it might be having trouble mapping to properties like the UserName property of the inherited User class, check your syntax for that type of mapping (i.e., User.UserName = ...). – nocturns2 Oct 20 '13 at 09:15
  • The problem was something strange in the RC version. The problem went away in RTM... – Piotr Stulinski Oct 21 '13 at 10:01

2 Answers2

0

if you are using version from the VS2013 release, change as follows.

public class ApplicationUser : User

to

public class ApplicationUser : IdentityUser

jd4u
  • 5,789
  • 2
  • 28
  • 28
0

This error happens in projects that have been generated in the RC version of Visual Studio 2013.

Go to your projects nuget packages folder, you will notice that a lot of them including EntityFramework are RC version.

Update all nuget packages to the latest release versions will solve the problem. (Note that some code changes will be required).

EDIT: Installing Microsoft.AspNet.Identity.EntityFramework was also required.

MichaelS
  • 7,023
  • 10
  • 51
  • 75