Kod struktury encji najpierw konwertuje między klasą boolean i kolumną integer

ja używamEntity Framework 5 code first. Moja tabela ma kolumnę o nazwieActive a jego typ danych jest typuint. Wartości przechowywane w Active są0, 1 inull.

Mam klasę, którą muszę zmapować na tę tabelę.

public class CommandExecutionServer : IEntity
{
     public int Id { get; set; }

     public bool? IsActive { get; set; }
}

Oto mój plik konfiguracyjny. Usiłuję odwzorować moją właściwość boolowską w mojej klasie na pole liczby całkowitej w bazie danych.

class CommandExecutionServerConfiguration : EntityTypeConfiguration<CommandExecutionServer>
{
     internal CommandExecutionServerConfiguration()
     {
          this.ToTable("tblCommandExecutionServers");
          this.Property(x => x.IsActive).HasColumnName("Active").HasColumnType("bit");
     }
}

To nie działa dobrze. Błąd, który otrzymuję:

The 'IsActive' property on 'CommandExecutionServer' could not be set to a 'Int32' value. You must set this property to a non-null value of type 'Boolean'

Próbowałem dodać.HasColumnType("bit") i pomyślałem, że może to zająć mój problem. Jak mam to zrobic? Idealnie chciałbym, aby 0 było fałszywe, 1 - prawda, null - null, a każda inna liczba - false.

AKTUALIZACJA

Jeśli zmienię powyższe na:

this.Property(x => x.IsActive).HasColumnName("Active").HasColumnType("int");

... wtedy pojawia się następujący błąd:

Member Mapping specified is not valid. The type 'Edm.Boolean[Nullable=True,DefaultValue=]' of member 'IsActive' in type 'MyProject.Infrastructure.EntityFramework.CommandExecutionServer' is not compatible with 'SqlServer.int[Nullable=True,DefaultValue=]' of member 'Active' in type 'CodeFirstDatabaseSchema.CommandExecutionServer'.

questionAnswers(2)

yourAnswerToTheQuestion