N.EntityFrameworkCore.Extensions
N.EntityFrameworkCore.Extensions copied to clipboard
Mapping with value converters(HasConversion) does not work
To Reproduce
- create table in database
CREATE SCHEMA [scm];
GO
CREATE TABLE [scm].[tbl](
[id] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[name] [nvarchar](120) NULL,
[color] [int] NULL,
) ON [PRIMARY]
GO
- define the class
class Item
{
public int Id {get;set;}
public string Name {get;set;}
public System.Drawing.Color Color {get;set;}
}
- override DbContext's OnModelCreating
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Item>(f =>
{
f.ToTable("tbl", "scm");
f.HasKey(x => x.Id);
f.Property(x => x.Id).IsRequired().ValueGeneratedOnAdd();
f.Property(x => x.Name);
f.Property(x => x.Color).HasConversion(x => x.ToArgb(), x => Color.FromArgb(x));
});
}
- test method
var items = new List<Item>();
for (var i = 1; i <= 1_000; ++i)
{
var item = new Item
{
Id = i,
Name = i.ToString(),
Color = Color.FromArgb(i)
};
items.Add(item);
}
context.BulkInsert(items);
context.BulkSaveChanges();
Expected behavior item.Color property should be converted to int before sending to database
osmozis,
This issue was addressed in v8.0.0.9