Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ public virtual void ProcessModelFinalizing(
{
Check.DebugAssert(readOnlyProperties.Count != 0, $"No properties mapped to column '{concurrencyColumnName}'");

// JSON-mapped entities don't have column names for their properties,
// so we skip them as they participate in the owner's concurrency token
if (entityType.IsMappedToJson())
{
continue;
}

var foundMappedProperty = !IsConcurrencyTokenMissing(readOnlyProperties, entityType, mappedTypes)
|| entityType.GetProperties()
.Any(p => p.GetColumnName(table) == concurrencyColumnName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,55 @@ public virtual void Concurrency_token_property_is_not_created_on_the_sharing_whe
Assert.All(animalEntityType.GetProperties(), p => Assert.NotEqual(typeof(byte[]), p.ClrType));
}

[ConditionalFact]
public virtual void Missing_concurrency_token_property_is_not_created_for_json_mapped_entity()
{
var modelBuilder = GetModelBuilder();
modelBuilder.Entity<BaseEntity>(b =>
{
b.HasKey(e => e.Id);
b.Property(e => e.RowVersion).IsRowVersion().IsConcurrencyToken();
b.Property(e => e.Name).HasMaxLength(100).IsRequired();
b.HasDiscriminator<string>("Type")
.HasValue<DerivedEntity>(nameof(DerivedEntity));
});
modelBuilder.Entity<DerivedEntity>(b =>
{
b.OwnsOne(x => x.Owned, ob =>
{
ob.ToJson();
ob.Property(o => o.Description).HasMaxLength(200).IsRequired();
});
});

var model = modelBuilder.Model;
model.FinalizeModel();

var ownedEntity = model.FindEntityType(typeof(OwnedEntity));
Assert.NotNull(ownedEntity);
Assert.True(ownedEntity.IsMappedToJson());
Assert.DoesNotContain(
ownedEntity.GetProperties(),
p => p.Name.StartsWith("_TableSharingConcurrencyTokenConvention"));
}

protected abstract class BaseEntity
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public long RowVersion { get; set; }
}

protected class DerivedEntity : BaseEntity
{
public OwnedEntity Owned { get; set; } = new();
}

protected class OwnedEntity
{
public string Description { get; set; } = "Any";
}

protected class Animal
{
public int Id { get; set; }
Expand Down