0

I am new to Entity Framework. I want to make it Database as a separate Entity In project. So I started my project with as Class Library project. Starting with Login so class created for it with inherit IdentityUser.

public class ApplicationUser : IdentityUser
{
    [Required]
    [MaxLength(200)]
    public string FirstName { get; set; }
    [Required]
    [MaxLength(500)]
    public string LastName { get; set; }
}

Now I want to create database , I have added key in App.Config.

public class AppDBContext : DbContext
{
    public AppDBContext():base("AppDBConnectionString")
    {

    }
}

Any Package Manager command to create database for first time ? Update-Database didnt work.

14
  • When you say "Update-Database didn't work.", what does that mean, exactly? did you receive some sort of error? Commented Jan 2, 2016 at 14:11
  • 1
    What version of Entity Framework are you using? EF7 had some major changes to how you create the database. Commented Jan 2, 2016 at 14:13
  • @Claies Specify the '-Verbose' flag to view the SQL statements being applied to the target database. No migrations configuration type was found in the assembly 'AspNetIdentity.Data'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration). Commented Jan 2, 2016 at 14:34
  • so it sounds like you haven't enabled migrations yet on your project. Commented Jan 2, 2016 at 14:34
  • @JosephGarrone Right now using EF6 , if EF7 has has new feature to creating database and managing easily . I can update that too. Commented Jan 2, 2016 at 14:35

1 Answer 1

1

Ok, to summarize, update your class to include a key:

public class ApplicationUser : IdentityUser
{
[Key]
public int ApplicationUserId { get; set; }

[Required]
[MaxLength(200)]
public string FirstName { get; set; }
[Required]
[MaxLength(500)]
public string LastName { get; set; }
}

And update your DbSet in your AppDbContext to:

DbSet<ApplicationUser> ApplicationUsers { get; set; }
Sign up to request clarification or add additional context in comments.

Comments

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.