我正在使用EF Code-First到现有的数据库方法,并IsActive在我的数据库中有一个字段.问题是该领域VARCHAR应该是什么时候boolean.我无法更改数据库架构.
数据库中的示例值为"Y" (true)或"N" (false)
映射时,我想将这些值转换为true/false,并使我的Entity类保持布尔值.
这可能吗?
我的实体和映射类如下,但我想将该IsActive字段更改为布尔值.
public class Employee
{
public int ID { get; set; }
public string SSN { get; set; }
public string Email { get; set; }
public string IsActive { get; set; }
}
public class EmployeeMap : EntityTypeConfiguration<Employee>
{
public EmployeeMap()
{
this.ToTable("Employees");
this.HasKey(t => t.ID);
this.Property(t => t.ID).HasColumnName("ID_Employee");
this.Property(t => t.SSN).HasColumnName("sReference");
this.Property(t => t.Email).HasColumnName("Email");
this.Property(t => t.IsActive).HasColumnName("IsActive");
} …Run Code Online (Sandbox Code Playgroud)