Files
OpenAuth.Net/OpenAuth.Repository/Mapping/UserMap.cs

68 lines
2.0 KiB
C#
Raw Normal View History

2015-04-15 23:57:36 +08:00
using System.Data.Entity.ModelConfiguration;
using OpenAuth.Domain;
2015-04-25 12:31:01 +08:00
using OpenAuth.Domain.Model;
2015-04-15 23:57:36 +08:00
2015-05-23 12:10:53 +08:00
namespace OpenAuth.Repository.Mapping
2015-04-15 23:57:36 +08:00
{
public class UserMap : EntityTypeConfiguration<User>
{
public UserMap()
{
// Primary Key
this.HasKey(t => t.Id);
2015-04-15 23:57:36 +08:00
// Properties
this.Property(t => t.Id)
2015-04-15 23:57:36 +08:00
.IsRequired()
.HasMaxLength(50);
this.Property(t => t.Account)
.HasMaxLength(50);
this.Property(t => t.Password)
.HasMaxLength(50);
this.Property(t => t.RealName)
.HasMaxLength(50);
this.Property(t => t.RoleId)
.HasMaxLength(50);
this.HasMany(u => u.Departments)
.WithMany(d => d.Users)
.Map(m =>
{
m.MapLeftKey("UserId");
m.MapRightKey("DepartmentId");
m.ToTable("UserDepartment");
});
2015-04-25 12:31:01 +08:00
this.HasMany(u => u.Roles)
.WithMany(r => r.Users)
.Map(m =>
{
m.MapLeftKey("UserId");
m.MapRightKey("RoleId");
m.ToTable("UserRole");
});
2015-04-27 00:10:02 +08:00
//Ĭ<>Ͻ<EFBFBD>ɫ
this.HasOptional(u => u.DefaultRole)
.WithMany()
.HasForeignKey(u =>u.RoleId);
2015-04-15 23:57:36 +08:00
// Table & Column Mappings
this.ToTable("User");
this.Property(t => t.Id).HasColumnName("UserId");
2015-04-15 23:57:36 +08:00
this.Property(t => t.Account).HasColumnName("Account");
this.Property(t => t.Password).HasColumnName("Password");
this.Property(t => t.RealName).HasColumnName("RealName");
this.Property(t => t.RoleId).HasColumnName("RoleId");
this.Property(t => t.Enabled).HasColumnName("Enabled");
this.Property(t => t.DeleteMark).HasColumnName("DeleteMark");
}
}
}