You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bulk insert create a wrong sql merge statement (was working with version 8)
See generated SQL where in the insert statement the data column is missing
MERGE [dbo].[Locations] WITH (HOLDLOCK) AS T USING
(SELECT TOP 1 * FROM [dbo].[LocationsTemp8d9864dc] ORDER BY [ExternalId]) AS S ON T.[ExternalId] = S.[ExternalId]
WHEN NOT MATCHED BY TARGET
THEN INSERT ([ConcernId], [CreatedDate], [DeletedDate], [ExternalId], [ModificationDate])
VALUES (S.[ConcernId], S.[CreatedDate], S.[DeletedDate], S.[ExternalId], S.[ModificationDate])
WHEN MATCHED AND EXISTS (SELECT S.[ConcernId], S.[CreatedDate], S.[Data], S.[DeletedDate], S.[ExternalId], S.[ModificationDate] EXCEPT SELECT T.[ConcernId], T.[CreatedDate], T.[Data], T.[DeletedDate], T.[ExternalId], T.[ModificationDate])
THEN UPDATE SET
T.[ConcernId] = S.[ConcernId],
T.[Data] = S.[Data],
T.[DeletedDate] = S.[DeletedDate],
T.[ExternalId] = S.[ExternalId],
T.[ModificationDate] = S.[ModificationDate];
go
c# code
var bulkConfig = new BulkConfig
{
UpdateByProperties = [nameof(Location.ExternalId)],
PropertiesToExcludeOnUpdate = [nameof(Location.CreatedDate), nameof(Concern.Id)]
};
await SetExternalIds(model);
await ctx.BulkInsertOrUpdateAsync(model, bulkConfig);
table
public int Id { get; set; }
public Concern Concern { get; set; } = null!;
public int ConcernId { get; set; }
public LocationData Data { get; set; } = new();
public DateTime CreatedDate { get; set; }
public DateTime ModificationDate { get; set; }
public DateTime? DeletedDate { get; set; }
public ICollection<LocationStartCode> StartCodes { get; set; } = new List<LocationStartCode>();
public int ExternalId { get; set; }
Where LocationData is een json string
See config
public void Configure(EntityTypeBuilder<Location> builder)
{
builder.HasIndex(x => x.ExternalId).IsUnique();
builder.Property(e => e.Data).HasConversion(
v => JsonSerializer.Serialize(v, JsonSerializerOptions),
v => JsonSerializer.Deserialize<LocationData>(v, (JsonSerializerOptions?)null)!);
builder.Property(x => x.Data).Metadata.SetValueComparerJson<LocationData>();
builder.Property(x => x.Data).HasDefaultValueSql("'{}'");
}
The text was updated successfully, but these errors were encountered:
Bulk insert create a wrong sql merge statement (was working with version 8)
See generated SQL where in the insert statement the data column is missing
c# code
table
Where LocationData is een json string
See config
The text was updated successfully, but these errors were encountered: