Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I used the answer to <a href="https://stackoverflow.com/questions/13327235/entity-framework-5-how-to-generate-poco-classes-from-existing-database">this question</a> to automatically generate the models from the existing 'webpage_' tables in my database. This ensures that the models are created in the exact same way that SimpleMembership creates them. This resulted in the following code:</p> <h2>Models:</h2> <pre><code>public partial class webpages_Membership { public int UserId { get; set; } public Nullable&lt;System.DateTime&gt; CreateDate { get; set; } public string ConfirmationToken { get; set; } public Nullable&lt;bool&gt; IsConfirmed { get; set; } public Nullable&lt;System.DateTime&gt; LastPasswordFailureDate { get; set; } public int PasswordFailuresSinceLastSuccess { get; set; } public string Password { get; set; } public Nullable&lt;System.DateTime&gt; PasswordChangedDate { get; set; } public string PasswordSalt { get; set; } public string PasswordVerificationToken { get; set; } public Nullable&lt;System.DateTime&gt; PasswordVerificationTokenExpirationDate { get; set; } } public partial class webpages_Roles { public webpages_Roles() { this.webpages_UsersInRoles = new HashSet&lt;webpages_UsersInRoles&gt;(); } public int RoleId { get; set; } public string RoleName { get; set; } public virtual ICollection&lt;webpages_UsersInRoles&gt; webpages_UsersInRoles { get; set; } } public partial class webpages_UsersInRoles { public int UserId { get; set; } public int RoleId { get; set; } public virtual webpages_Roles webpages_Roles { get; set; } } </code></pre> <h2>Fluent Mappings:</h2> <pre><code>internal partial class MembershipMapping : EntityTypeConfiguration&lt;webpages_Membership&gt; { public MembershipMapping() { this.HasKey(t =&gt; t.UserId); this.ToTable("webpages_Membership"); this.Property(t =&gt; t.UserId).HasColumnName("UserId").HasDatabaseGeneratedOption(new Nullable&lt;DatabaseGeneratedOption&gt;(DatabaseGeneratedOption.None)); this.Property(t =&gt; t.CreateDate).HasColumnName("CreateDate"); this.Property(t =&gt; t.ConfirmationToken).HasColumnName("ConfirmationToken").HasMaxLength(128); this.Property(t =&gt; t.IsConfirmed).HasColumnName("IsConfirmed"); this.Property(t =&gt; t.LastPasswordFailureDate).HasColumnName("LastPasswordFailureDate"); this.Property(t =&gt; t.PasswordFailuresSinceLastSuccess).HasColumnName("PasswordFailuresSinceLastSuccess"); this.Property(t =&gt; t.Password).HasColumnName("Password").IsRequired().HasMaxLength(128); this.Property(t =&gt; t.PasswordChangedDate).HasColumnName("PasswordChangedDate"); this.Property(t =&gt; t.PasswordSalt).HasColumnName("PasswordSalt").IsRequired().HasMaxLength(128); this.Property(t =&gt; t.PasswordVerificationToken).HasColumnName("PasswordVerificationToken").HasMaxLength(128); this.Property(t =&gt; t.PasswordVerificationTokenExpirationDate).HasColumnName("PasswordVerificationTokenExpirationDate"); } } internal partial class RolesMapping : EntityTypeConfiguration&lt;webpages_Roles&gt; { public RolesMapping() { this.HasKey(t =&gt; t.RoleId); this.ToTable("webpages_Roles"); this.Property(t =&gt; t.RoleId).HasColumnName("RoleId"); this.Property(t =&gt; t.RoleName).HasColumnName("RoleName").IsRequired().HasMaxLength(256); } } internal partial class UsersInRolesMapping : EntityTypeConfiguration&lt;webpages_UsersInRoles&gt; { public UsersInRolesMapping() { this.HasKey(t =&gt; new { t.UserId, t.RoleId }); this.ToTable("webpages_UsersInRoles"); this.Property(t =&gt; t.UserId).HasColumnName("UserId").HasDatabaseGeneratedOption(new Nullable&lt;DatabaseGeneratedOption&gt;(DatabaseGeneratedOption.None)); this.Property(t =&gt; t.RoleId).HasColumnName("RoleId").HasDatabaseGeneratedOption(new Nullable&lt;DatabaseGeneratedOption&gt;(DatabaseGeneratedOption.None)); this.HasRequired(t =&gt; t.webpages_Roles).WithMany(t =&gt; t.webpages_UsersInRoles).HasForeignKey(d =&gt; d.RoleId); } } </code></pre> <h2>Database Context:</h2> <pre><code>public class MembershipContext : DbContext, IDisposable { public DbSet&lt;webpages_Membership&gt; Membership { get; set; } public DbSet&lt;webpages_Roles&gt; Roles { get; set; } public DbSet&lt;webpages_UsersInRoles&gt; UsersInRoles { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new MembershipMapping()); modelBuilder.Configurations.Add(new RolesMapping()); modelBuilder.Configurations.Add(new UsersInRolesMapping()); base.OnModelCreating(modelBuilder); } } </code></pre> <p>Note that I have excluded the OAuthMembership table, because I didn't need it for my solution. But if you follow the steps in the link I provided above you can easily include that table as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload