Hi!, I want to use simple membership with my EF 5 project.
say my context currently looks like this
public class DB : DbContext, IDbContext
{
public DB()
: base("db")
{
}
public DbSet<Company> Companies { get; set; }
public DbSet<User> CustomProfiles { get; set; }
public DbSet<ServiceProvider> ServiceProviders { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<DB, Configuration>());
base.OnModelCreating(modelBuilder);
}
in order to get the web security initialised do I just add this after the line base.OnModelCreating(modelBuilder);? :
try
{
using (var context = new DB())
{
if (!context.Database.Exists())
{
// Create the SimpleMembership database without Entity Framework migration schema
((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
}
}
WebSecurity.InitializeDatabaseConnection("db", "UserProfile", "UserId", "UserName", autoCreateTables: true);
}
catch (Exception ex)
{
throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
}
GorillaMann
Member
117 Points
332 Posts
Using simple membership with an existing EF 5 code first project.
Jan 10, 2013 03:09 PM|LINK
Hi!, I want to use simple membership with my EF 5 project.
say my context currently looks like this
public class DB : DbContext, IDbContext { public DB() : base("db") { } public DbSet<Company> Companies { get; set; } public DbSet<User> CustomProfiles { get; set; } public DbSet<ServiceProvider> ServiceProviders { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { Database.SetInitializer(new MigrateDatabaseToLatestVersion<DB, Configuration>()); base.OnModelCreating(modelBuilder); }in order to get the web security initialised do I just add this after the line base.OnModelCreating(modelBuilder);? :
try { using (var context = new DB()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } WebSecurity.InitializeDatabaseConnection("db", "UserProfile", "UserId", "UserName", autoCreateTables: true); } catch (Exception ex) { throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex); }Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Using simple membership with an existing EF 5 code first project.
Jan 12, 2013 03:12 AM|LINK
Hi,
Yes, I think so. If you don't call this, I'm afraid you cannot create from model entity to a real table.
Reguards!
GorillaMann
Member
117 Points
332 Posts
Re: Using simple membership with an existing EF 5 code first project.
Jan 12, 2013 12:08 PM|LINK
I found that I had to stick it here:
protected void Application_Start() { WebSecurity.InitializeDatabaseConnection("CrowdFundingDB", "Users", "UserId", "UserName",