public static void Should_not_throw_InvalidOperationException_when_using_enum_as_discriminator(ConversionStrategy conversionStrategy, bool applyColumnType) { var options = new DbContextOptionsBuilder() .UseSqlServer($"Data Source=(local);Initial Catalog=Test_{nameof(MsftDocsValueConversionExample)}_{conversionStrategy}_{applyColumnType};Integrated Security=SSPI;").Options; using (var db = new TestContext(options, conversionStrategy, applyColumnType)) { db.Database.EnsureDeleted(); db.Database.EnsureCreated(); // TODO write save logic var rider = new Rider() { Mount = EquineBeast.Horse }; db.Add(rider); db.SaveChanges(); var sameRider = db.Set <Rider>().FirstOrDefault(r => r.Id == rider.Id); Assert.True(sameRider != null); var sameRider2 = db.Set <Rider>().FirstOrDefault(r => r.Mount == EquineBeast.Horse); Assert.True(sameRider2 != null); } }
public TestContext(DbContextOptions options, ConversionStrategy conversionStrategy, bool applyColumnType) : base(options) { _conversionStrategy = conversionStrategy; _applyColumnType = applyColumnType; }
/// <summary> /// Gets the value from strategy. /// </summary> /// <param name="value"> The value. </param> /// <param name="strategy"> The strategy. </param> /// <returns> </returns> private static string GetValueFromStrategy(object value, ConversionStrategy strategy) { switch (strategy) { case ConversionStrategy.StringList: return string.Join(",", ((List<string>) value)); default: return value.ToString(); } }