Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit e202054

Browse files
committed
Fix for #30. Disabled automatic conversion generator for enums.
1 parent 120e8f1 commit e202054

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ public virtual void DefineConvertors(
391391

392392
foreach (var clrType in types)
393393
{
394+
// skipping enums
395+
if (clrType.IsEnum)
396+
continue;
397+
394398
var currentType = mappingSchema.GetDataType(clrType);
395399
if (currentType != SqlDataType.Undefined)
396400
continue;

Tests/LinqToDB.EntityFrameworkCore.Tests/JsonConverTests.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using LinqToDB.Data;
34
using Microsoft.EntityFrameworkCore;
45
using Newtonsoft.Json;
@@ -24,9 +25,17 @@ public class EventScheduleItemBase
2425
public int Id { get; set; }
2526
public virtual LocalizedString NameLocalized { get; set; }
2627
}
28+
29+
public enum CrashEnum : byte
30+
{
31+
OneValue = 0,
32+
OtherValue = 1
33+
}
2734

2835
public class EventScheduleItem : EventScheduleItemBase
2936
{
37+
public CrashEnum CrashEnum { get; set; }
38+
public Guid GuidColumn { get; set; }
3039
}
3140

3241
public class JsonConvertContext : DbContext
@@ -58,6 +67,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
5867
.HasColumnName("NameLocalized_JSON")
5968
.HasConversion(v => JsonConvert.SerializeObject(v),
6069
v => JsonConvert.DeserializeObject<LocalizedString>(v));
70+
entity.Property(e => e.CrashEnum).HasColumnType("tinyint");
71+
entity.Property(e => e.GuidColumn).HasColumnType("uniqueidentifier");
6172
});
6273
}
6374
}
@@ -86,13 +97,15 @@ public void TestJsonConvert()
8697

8798
using (var ctx = new JsonConvertContext(_options))
8899
{
100+
ctx.Database.EnsureDeleted();
89101
ctx.Database.EnsureCreated();
90102

91103
ctx.EventScheduleItems.Delete();
92104

93105
ctx.EventScheduleItems.Add(new EventScheduleItem()
94106
{
95-
NameLocalized = new LocalizedString() { English = "English", German = "German", Slovak = "Slovak" }
107+
NameLocalized = new LocalizedString() { English = "English", German = "German", Slovak = "Slovak" },
108+
GuidColumn = Guid.NewGuid()
96109
});
97110
ctx.SaveChanges();
98111

@@ -103,7 +116,9 @@ public void TestJsonConvert()
103116
.Select(p => new
104117
{
105118
p.Id,
106-
p.NameLocalized
119+
p.NameLocalized,
120+
p.CrashEnum,
121+
p.GuidColumn
107122
}).FirstOrDefault();
108123

109124
Assert.That(item.NameLocalized.English, Is.EqualTo("English"));

0 commit comments

Comments
 (0)