1

I'm trying to move my DbSet's to a class library project that is going to be used for database operations.

I've been following this tutorial to a Code First / SimpleMembershipProfider project. I've already got the database filled with new tables etc, via the class lib project.

But i am missing the webpages_ tables you can see on this image.

This is my datacontext class:

public class DataContext : DbContext
{
    public DataContext() : base("DefaultConnection")
    {
    }

    public DbSet<Orders> Orders { get; set; }
    public DbSet<Appointment> Appointment { get; set; }
    public DbSet<UserProfile> UserProfile { get; set; }
}

And for every DbSet i created a cs file. I copied the connectionString from the web.config and placed it in the app.config in the class lib project. This is how the app.config file looks like:

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.;Initial Catalog=aspnet-CodeFirst-test;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <roleManager enabled="true" defaultProvider="SimpleRoleProvider">
      <providers>
        <clear />
        <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
      </providers>
    </roleManager>
    <membership defaultProvider="SimpleMembershipProvider">
      <providers>
        <clear />
        <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData"  />
      </providers>
    </membership>
  </system.web>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

I'm not sure what to do with the Filters folder (which has the class InitializeSimpleMembershipAttribute) in my webproject.

Can someone tell me how to get the webpages_ created in the database? And how to move websecurity etc to the class lib project?

Thanks in advance!

Yustme
  • 5,455
  • 21
  • 69
  • 100
  • Are you trying to take control of `SimpleMembership` and Including it in your project entity framework? – Komengem May 05 '13 at 17:03

1 Answers1

1

If you trying to take control of Asp.net Simple Membership Table and or Including Asp.net Simple Membership Tables as Part of Your Entity Framework Model your Project Entity framework, there is a number of steps you need to take. I would explain them step by step but it would take too long so i will just provide you with references.

Including Asp.net Simple Membership Tables as Part of Your Entity Framework Model

Seed Users and Roles with MVC 4, SimpleMembershipProvider, SimpleRoleProvider, Entity Framework 5 CodeFirst, and Custom User Properties

Building Applications with ASP.NET MVC 4. You can use trial version on pluralsight

If you have any specific questions, i would be happy to answer them.

Komengem
  • 3,496
  • 6
  • 31
  • 56
  • Hi, so i see that i have to create the tables "webpages_Membership" and roles and oauth etc, myself. In the second link, the tutorial i followed, i didn't see any of these 4 tables being created? Another question i have is, if i want to seed users etc from my class library project, what do i have to create there to make it happen? – Yustme May 05 '13 at 17:41
  • @Yustme You manually create tables so that you have control and you can place them wherever you want them. That way, you can use same connection string for your entire application. To seed users you would have to enable migrations, 2nd link talks about this. – Komengem May 05 '13 at 17:45
  • Lots of peaces just fell into their places. Thanks! – Yustme May 05 '13 at 20:35
  • @Yustme I am glad to know that this was helpful. – Komengem May 05 '13 at 23:01