0

I’m trying to build database using schema first (EF5) and add it simple membership as well.

After ”drawing” my schema I have add user profile table (UserId&UserName) remove the

Filter: InitializeSimpleMembershipAttribute, remove all of this ..

//public class UsersContext : DbContext
//{
//    public UsersContext()
//        : base("DefaultConnection")
//    {
//    }

//    public DbSet<UserProfile> UserProfiles { get; set; }

//}

//[Table("UserProfile")]
//public class UserProfile
//{
//    [Key]
//    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
//    public int UserId { get; set; }
//    public string UserName { get; set; }
//}

In the generated class (by schema first) I have tried to add manually

[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]

to my UserProfile class

I have also register in my AppStart :

WebSecurity.InitializeDatabaseConnection("Model1Container", "UserProfile",
    "UserId", "UserName", autoCreateTables: true);

But on debug I’m getting this error :

Unable to find the requested .Net Framework Data Provider.  It may not be installed

WebSecurity.InitializeDatabaseConnection("Model1Container", "UserProfile",

Is there a good practice how to do it ?

Is it possible using schema first ?

Danny
  • 301
  • 1
  • 4
  • 21

1 Answers1

0

Notice , you have removed following part which had the connection name.

public UsersContext()
//        : base("DefaultConnection")
//    {
//    }

Just add that in your context class. And Yes , you can do it using Code first Approach and I think it is a lot easier than what your are doing now..

Bhushan Firake
  • 9,338
  • 5
  • 44
  • 79