Skip to content

Commit

Permalink
Fix to #30516 - Query: JSON collection issues incorrect warning Compo…
Browse files Browse the repository at this point in the history
…siteKeyWithValueGeneration (#30517)

Don't issue the warning for entities mapped to JSON.

Fixes #30516
  • Loading branch information
maumar committed Mar 20, 2023
1 parent 2ba7dcd commit 9d324b4
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public override void Validate(IModel model, IDiagnosticsLogger<DbLoggerCategory.
base.ValidateValueGeneration(entityType, key, logger);

var keyProperties = key.Properties;
if (key.IsPrimaryKey()
if (!entityType.IsMappedToJson()
&& key.IsPrimaryKey()
&& keyProperties.Count(p => p.ClrType.UnwrapNullableType().IsInteger()) > 1
&& keyProperties.Any(
p => p.ValueGenerated == ValueGenerated.OnAdd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ protected override string StoreName
public virtual async Task Optional_json_properties_materialized_as_null_when_the_element_in_json_is_not_present(bool async)
{
var contextFactory = await InitializeAsync<MyContext29219>(
onConfiguring: OnConfiguring29219,
seed: Seed29219);

using (var context = contextFactory.CreateContext())
Expand All @@ -42,7 +41,6 @@ public virtual async Task Optional_json_properties_materialized_as_null_when_the
public virtual async Task Can_project_nullable_json_property_when_the_element_in_json_is_not_present(bool async)
{
var contextFactory = await InitializeAsync<MyContext29219>(
onConfiguring: OnConfiguring29219,
seed: Seed29219);

using (var context = contextFactory.CreateContext())
Expand All @@ -60,10 +58,6 @@ public virtual async Task Can_project_nullable_json_property_when_the_element_in
}
}

protected virtual void OnConfiguring29219(DbContextOptionsBuilder builder)
{
}

protected abstract void Seed29219(MyContext29219 ctx);

protected class MyContext29219 : DbContext
Expand Down Expand Up @@ -100,10 +94,6 @@ public class MyJsonEntity29219

#region 30028

protected virtual void OnConfiguring30028(DbContextOptionsBuilder builder)
{
}

protected abstract void Seed30028(MyContext30028 ctx);

protected class MyContext30028 : DbContext
Expand Down Expand Up @@ -238,7 +228,6 @@ public virtual async Task Missing_navigation_works_with_deduplication(bool async
public virtual async Task Project_json_array_of_primitives_on_reference(bool async)
{
var contextFactory = await InitializeAsync<MyContextArrayOfPrimitives>(
onConfiguring: OnConfiguringArrayOfPrimitives,
seed: SeedArrayOfPrimitives);

using (var context = contextFactory.CreateContext())
Expand All @@ -262,7 +251,6 @@ public virtual async Task Project_json_array_of_primitives_on_reference(bool asy
public virtual async Task Project_json_array_of_primitives_on_collection(bool async)
{
var contextFactory = await InitializeAsync<MyContextArrayOfPrimitives>(
onConfiguring: OnConfiguringArrayOfPrimitives,
seed: SeedArrayOfPrimitives);

using (var context = contextFactory.CreateContext())
Expand All @@ -286,7 +274,6 @@ public virtual async Task Project_json_array_of_primitives_on_collection(bool as
public virtual async Task Project_element_of_json_array_of_primitives(bool async)
{
var contextFactory = await InitializeAsync<MyContextArrayOfPrimitives>(
onConfiguring: OnConfiguringArrayOfPrimitives,
seed: SeedArrayOfPrimitives);

using (var context = contextFactory.CreateContext())
Expand All @@ -308,7 +295,6 @@ public virtual async Task Project_element_of_json_array_of_primitives(bool async
public virtual async Task Predicate_based_on_element_of_json_array_of_primitives1(bool async)
{
var contextFactory = await InitializeAsync<MyContextArrayOfPrimitives>(
onConfiguring: OnConfiguringArrayOfPrimitives,
seed: SeedArrayOfPrimitives);

using (var context = contextFactory.CreateContext())
Expand All @@ -331,7 +317,6 @@ public virtual async Task Predicate_based_on_element_of_json_array_of_primitives
public virtual async Task Predicate_based_on_element_of_json_array_of_primitives2(bool async)
{
var contextFactory = await InitializeAsync<MyContextArrayOfPrimitives>(
onConfiguring: OnConfiguringArrayOfPrimitives,
seed: SeedArrayOfPrimitives);
using (var context = contextFactory.CreateContext())
Expand All @@ -354,7 +339,6 @@ public virtual async Task Predicate_based_on_element_of_json_array_of_primitives
public virtual async Task Predicate_based_on_element_of_json_array_of_primitives3(bool async)
{
var contextFactory = await InitializeAsync<MyContextArrayOfPrimitives>(
onConfiguring: OnConfiguringArrayOfPrimitives,
seed: SeedArrayOfPrimitives);
using (var context = contextFactory.CreateContext())
Expand All @@ -376,10 +360,6 @@ public virtual async Task Predicate_based_on_element_of_json_array_of_primitives

protected abstract void SeedArrayOfPrimitives(MyContextArrayOfPrimitives ctx);

protected virtual void OnConfiguringArrayOfPrimitives(DbContextOptionsBuilder builder)
{
}

protected class MyContextArrayOfPrimitives : DbContext
{
public MyContextArrayOfPrimitives(DbContextOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,5 @@ protected override ITestStoreFactory TestStoreFactory
IServiceCollection serviceCollection,
IEnumerable<ISingletonInterceptor> injectedInterceptors)
=> base.InjectInterceptors(serviceCollection.AddEntityFrameworkSqlite(), injectedInterceptors);

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder.ConfigureWarnings(e => e.Ignore(SqliteEventId.CompositeKeyWithValueGeneration)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ public JsonQueryAdHocSqliteTest(ITestOutputHelper testOutputHelper)
protected override ITestStoreFactory TestStoreFactory
=> SqliteTestStoreFactory.Instance;

// issue #26708
protected override void OnConfiguring29219(DbContextOptionsBuilder builder)
=> base.AddOptions(builder.ConfigureWarnings(b => b.Ignore(SqliteEventId.CompositeKeyWithValueGeneration)));

protected override void Seed29219(MyContext29219 ctx)
{
var entity1 = new MyEntity29219
Expand Down Expand Up @@ -48,10 +44,6 @@ protected override void Seed29219(MyContext29219 ctx)
VALUES(3, '{{ ""NonNullableScalar"" : 30 }}', '[{{ ""NonNullableScalar"" : 10001 }}]')");
}

// issue #26708
protected override void OnConfiguring30028(DbContextOptionsBuilder builder)
=> base.AddOptions(builder.ConfigureWarnings(b => b.Ignore(SqliteEventId.CompositeKeyWithValueGeneration)));

protected override void Seed30028(MyContext30028 ctx)
{
// complete
Expand Down Expand Up @@ -79,10 +71,6 @@ protected override void Seed30028(MyContext30028 ctx)
'{{""RootName"":""e4"",""Collection"":[{{""BranchName"":""e4 c1"",""Nested"":{{""LeafName"":""e4 c1 l""}}}},{{""BranchName"":""e4 c2"",""Nested"":{{""LeafName"":""e4 c2 l""}}}}],""OptionalReference"":{{""BranchName"":""e4 or"",""Nested"":{{""LeafName"":""e4 or l""}}}}}}')");
}

// issue #26708
protected override void OnConfiguringArrayOfPrimitives(DbContextOptionsBuilder builder)
=> base.AddOptions(builder.ConfigureWarnings(b => b.Ignore(SqliteEventId.CompositeKeyWithValueGeneration)));

protected override void SeedArrayOfPrimitives(MyContextArrayOfPrimitives ctx)
{
var entity1 = new MyEntityArrayOfPrimitives
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,4 @@ public class JsonQuerySqliteFixture : JsonQueryFixtureBase
{
protected override ITestStoreFactory TestStoreFactory
=> SqliteTestStoreFactory.Instance;


// issue #26708
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder.ConfigureWarnings(b => b.Ignore(SqliteEventId.CompositeKeyWithValueGeneration)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ public class JsonUpdateSqliteFixture : JsonUpdateFixtureBase
{
protected override ITestStoreFactory TestStoreFactory
=> SqliteTestStoreFactory.Instance;

// issue #26708
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> base.AddOptions(builder.ConfigureWarnings(b => b.Ignore(SqliteEventId.CompositeKeyWithValueGeneration)));
}

0 comments on commit 9d324b4

Please sign in to comment.