EnVisageOnline/Beta/Source/IntegrationTests/Models/Mapping/CompanyMap.cs

32 lines
919 B
C#

using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
namespace IntegrationTests.Models.Mapping
{
public class CompanyMap : EntityTypeConfiguration<Company>
{
public CompanyMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Name)
.IsRequired()
.HasMaxLength(200);
// Table & Column Mappings
this.ToTable("Company");
this.Property(t => t.Id).HasColumnName("Id");
this.Property(t => t.Name).HasColumnName("Name");
this.Property(t => t.ParentCompanyId).HasColumnName("ParentCompanyId");
// Relationships
this.HasOptional(t => t.Company2)
.WithMany(t => t.Company1)
.HasForeignKey(d => d.ParentCompanyId);
}
}
}