OpenAuth.Net/OpenAuth.Repository/Mapping/DepartmentMap.cs

52 lines
1.6 KiB
C#
Raw Normal View History

2015-04-15 23:57:36 +08:00
using System.Data.Entity.ModelConfiguration;
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 DepartmentMap : EntityTypeConfiguration<Department>
{
public DepartmentMap()
{
// Primary Key
2015-05-23 12:10:53 +08:00
this.HasKey(t => t.Id);
2015-04-15 23:57:36 +08:00
// Properties
2015-05-23 12:10:53 +08:00
this.Property(t => t.Id)
2015-04-15 23:57:36 +08:00
.IsRequired()
.HasMaxLength(50);
this.HasMany(d => d.Users)
.WithMany(u => u.Departments)
.Map(
m =>
{
m.MapLeftKey("DepartmentId");
m.MapRightKey("UserId");
m.ToTable("UserDepartment");
});
this.HasMany(d => d.Roles)
.WithRequired(r => r.Department);
this.Property(t => t.ParentId)
.HasMaxLength(50);
this.Property(t => t.FullName)
.HasMaxLength(50);
this.Property(t => t.Description)
.HasMaxLength(50);
// Table & Column Mappings
this.ToTable("Department");
2015-05-23 12:10:53 +08:00
this.Property(t => t.Id).HasColumnName("DepartmentId");
2015-04-15 23:57:36 +08:00
this.Property(t => t.ParentId).HasColumnName("ParentId");
this.Property(t => t.FullName).HasColumnName("FullName");
this.Property(t => t.Description).HasColumnName("Description");
this.Property(t => t.Enabled).HasColumnName("Enabled");
this.Property(t => t.SortCode).HasColumnName("SortCode");
this.Property(t => t.DeleteMark).HasColumnName("DeleteMark");
}
}
}