EF Code First Oracle Map Char(1) to Bool
Posted: Thu 23 May 2013 21:47
I am using EF Code First with Oracle and i want to map Char(1) to bool. The values are 'S' for true and 'N' for false
Discussion forums for open issues and questions concerning database tools, data access components and developer tools from Devart
https://forums.devart.com/
degas wrote:I am using EF Code First with Oracle and i want to map Char(1) to bool.
Code: Select all
public class BoolTable {
public int Id { get; set; }
[Column(TypeName = "yes no char as boolean")]
public bool CharBasedBoolean { get; set; }
}
public class MyContext: DbContext {
public DbSet<BoolTable> BoolTable { get; set; }
// ...
}
Code: Select all
CREATE TABLE "BoolTables" (
"Id" NUMBER(10) NOT NULL,
"CharBasedBoolean" CHAR(1) NOT NULL,
PRIMARY KEY ("Id")
)
Code: Select all
public class MyContext : DbContext {
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
modelBuilder
.Properties()
.Where(p => p.PropertyType == typeof(Boolean))
.Configure(p => p.HasColumnType("yes no char as boolean"));
}
// ...
}
Our solution works only for mapping System.Boolean to CHAR(1) with values 'Y' for true and 'N' for false.dumian wrote:How was the Problem Solved to use 'S' instead of 'Y' , because we have an simillar case to use 'J' instead of 'Y' ?