public void BatchUpdate_EntityUsingBuiltInEnumToStringConverter_UpdatesDatabaseWithEnumStringValue(DbServer dbServer) { ContextUtil.DbServer = dbServer; using var db = new VcDbContext(ContextUtil.GetOptions <VcDbContext>(databaseName: $"{nameof(EFCoreBulkTest)}_ValueConverters")); db.BulkInsertOrUpdate(this.GetTestData().ToList()); var date = new LocalDate(2020, 3, 21); db.VcModels.Where(x => x.LocalDate > date).BatchUpdate(x => new VcModel { Enum = VcEnum.Why }); var connection = db.Database.GetDbConnection(); connection.Open(); using var cmd = connection.CreateCommand(); cmd.CommandText = "SELECT * FROM VcModels ORDER BY Id DESC"; cmd.CommandType = System.Data.CommandType.Text; using var reader = cmd.ExecuteReader(); reader.Read(); var enumStr = reader.Field <string>("Enum"); Assert.Equal(VcEnum.Why.ToString(), enumStr); }
public void BatchDelete_UsingWhereExpressionWithValueConverter_Deletes(DbServer dbServer) { ContextUtil.DbServer = dbServer; using var db = new VcDbContext(ContextUtil.GetOptions <VcDbContext>(databaseName: $"{nameof(EFCoreBulkTest)}_ValueConverters")); db.BulkInsertOrUpdate(this.GetTestData().ToList()); var date = new LocalDate(2020, 3, 21); db.VcModels.Where(x => x.LocalDate > date).BatchDelete(); var models = db.VcModels.Count(); Assert.Equal(0, models); }
public void BulkInsertOrUpdate_EntityUsingBuiltInEnumToStringConverter_SavesToDatabase(DbServer databaseType) { ContextUtil.DbServer = databaseType; using var db = new VcDbContext(ContextUtil.GetOptions <VcDbContext>(databaseName: $"{nameof(EFCoreBulkTest)}_ValueConverters")); db.BulkInsertOrUpdate(this.GetTestData(db).ToList()); var connection = db.Database.GetDbConnection(); connection.Open(); using var cmd = connection.CreateCommand(); cmd.CommandText = "SELECT * FROM VcModels ORDER BY Id DESC"; cmd.CommandType = System.Data.CommandType.Text; using var reader = cmd.ExecuteReader(); reader.Read(); var enumStr = reader.Field <string>("Enum"); Assert.Equal(VcEnum.Hello.ToString(), enumStr); }