Skip to content

Commit 7a7df5f

Browse files
authored
Update exception messages for optional dependents (#24602)
Address PR feedback
1 parent 0a7ad48 commit 7a7df5f

File tree

19 files changed

+182
-95
lines changed

19 files changed

+182
-95
lines changed

src/EFCore.Relational/Properties/RelationalStrings.Designer.cs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/EFCore.Relational/Properties/RelationalStrings.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,8 @@
551551
<comment>Debug RelationalEventId.ConnectionOpening string string</comment>
552552
</data>
553553
<data name="LogOptionalDependentWithoutIdentifyingProperty" xml:space="preserve">
554-
<value>Entity type '{entityType}' is an optional dependent in table sharing without any required non shared property to identify if the entity type exist. If all nullable properties contain null value in database then an object instance won't be materialized in the query.</value>
555-
<comment>Error RelationalEventId.ModelValidationOptionalDependentWithoutIdentifyingPropertyWarning string</comment>
554+
<value>The entity type '{entityType}' is an optional dependent using table sharing without any required non shared property that could be used to identify whether the entity exists. If all nullable properties contain a null value in database then an object instance won't be created in the query. Add a required property to create instances with null values for other properties or mark the incoming navigation as required to always create an instance.</value>
555+
<comment>Warning RelationalEventId.OptionalDependentWithoutIdentifyingPropertyWarning string</comment>
556556
</data>
557557
<data name="LogPossibleUnintendedUseOfEquals" xml:space="preserve">
558558
<value>Possible unintended use of method 'Equals' for arguments '{left}' and '{right}' of different types in a query. This comparison will always return false.</value>
@@ -680,7 +680,7 @@
680680
<value>Expression '{sqlExpression}' in the SQL tree does not have a type mapping assigned.</value>
681681
</data>
682682
<data name="OptionalDependentWithDependentWithoutIdentifyingProperty" xml:space="preserve">
683-
<value>Entity type '{entityType}' is an optional dependent containing other dependents in table sharing without any required non shared property to identify if the entity type exist. If all nullable properties contain null value in database then an object instance won't be materialized in the query causing nested dependent's values to be lost.</value>
683+
<value>Entity type '{entityType}' is an optional dependent using table sharing and containing other dependents without any required non shared property to identify whether the entity exists. If all nullable properties contain a null value in database then an object instance won't be created in the query causing nested dependent's values to be lost. Add a required property to create instances with null values for other properties or mark the incoming navigation as required to always create an instance.</value>
684684
</data>
685685
<data name="ParameterNotObjectArray" xml:space="preserve">
686686
<value>Cannot use the value provided for parameter '{parameter}' because it isn't assignable to type object[].</value>

test/EFCore.Relational.Specification.Tests/TableSplittingTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public virtual async Task Can_insert_dependent_with_just_one_parent()
378378
context.Add(
379379
new FuelTank
380380
{
381-
Capacity = "10000 l",
381+
Capacity = 10000_1,
382382
FuelType = "Gas",
383383
VehicleName = "Fuel transport"
384384
});

test/EFCore.Relational.Tests/Infrastructure/RelationalModelValidatorTest.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public virtual void Passes_on_not_configured_shared_columns_with_shared_table()
335335
}
336336

337337
[ConditionalFact]
338-
public virtual void Throws_on_not_configured_shared_columns_with_shared_table()
338+
public virtual void Throws_on_not_configured_shared_columns_with_shared_table_with_dependents()
339339
{
340340
var modelBuilder = CreateConventionalModelBuilder();
341341

@@ -348,6 +348,17 @@ public virtual void Throws_on_not_configured_shared_columns_with_shared_table()
348348
VerifyError(RelationalStrings.OptionalDependentWithDependentWithoutIdentifyingProperty(nameof(A)), modelBuilder.Model);
349349
}
350350

351+
[ConditionalFact]
352+
public virtual void Warns_on_not_configured_shared_columns_with_shared_table()
353+
{
354+
var modelBuilder = CreateConventionalModelBuilder();
355+
356+
modelBuilder.Entity<Owner>().OwnsOne(e => e.Owned);
357+
358+
var definition = RelationalResources.LogOptionalDependentWithoutIdentifyingProperty(new TestLogger<TestRelationalLoggingDefinitions>());
359+
VerifyWarning(definition.GenerateMessage(nameof(OwnedEntity)), modelBuilder.Model);
360+
}
361+
351362
[ConditionalFact]
352363
public virtual void Detects_incompatible_shared_columns_with_shared_table()
353364
{
@@ -2000,6 +2011,17 @@ protected class Employee : Person
20002011
{
20012012
}
20022013

2014+
protected class Owner
2015+
{
2016+
public int Id { get; set; }
2017+
public OwnedEntity Owned { get; set; }
2018+
}
2019+
2020+
protected class OwnedEntity
2021+
{
2022+
public string Value { get; set; }
2023+
}
2024+
20032025
public class TestDecimalToLongConverter : ValueConverter<decimal, long>
20042026
{
20052027
private static readonly Expression<Func<decimal, long>> convertToProviderExpression = d => (long)(d * 100);

test/EFCore.Specification.Tests/DataAnnotationTestBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,7 @@ public class StreetAddress
24862486
{
24872487
public string Street { get; set; }
24882488
public string City { get; set; }
2489+
public int ZipCode { get; set; }
24892490
}
24902491

24912492
public class Order
@@ -2630,6 +2631,7 @@ protected class Two
26302631
[Owned]
26312632
protected class Details
26322633
{
2634+
public int Value { get; set; }
26332635
public string Name { get; set; }
26342636
}
26352637

test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,42 +2083,51 @@ public virtual void Can_serialize_proxies_to_JSON()
20832083
{
20842084
""Writer"": {
20852085
""FirstName"": ""firstNameWriter0"",
2086-
""LastName"": ""lastNameWriter0""
2086+
""LastName"": ""lastNameWriter0"",
2087+
""Alive"": false
20872088
},
20882089
""Reader"": {
20892090
""FirstName"": ""firstNameReader0"",
2090-
""LastName"": ""lastNameReader0""
2091+
""LastName"": ""lastNameReader0"",
2092+
""Alive"": false
20912093
},
20922094
""Host"": {
2093-
""HostName"": ""127.0.0.1""
2095+
""HostName"": ""127.0.0.1"",
2096+
""Rating"": 0.0
20942097
},
20952098
""Id"": 1
20962099
},
20972100
{
20982101
""Writer"": {
20992102
""FirstName"": ""firstNameWriter1"",
2100-
""LastName"": ""lastNameWriter1""
2103+
""LastName"": ""lastNameWriter1"",
2104+
""Alive"": false
21012105
},
21022106
""Reader"": {
21032107
""FirstName"": ""firstNameReader1"",
2104-
""LastName"": ""lastNameReader1""
2108+
""LastName"": ""lastNameReader1"",
2109+
""Alive"": false
21052110
},
21062111
""Host"": {
2107-
""HostName"": ""127.0.0.2""
2112+
""HostName"": ""127.0.0.2"",
2113+
""Rating"": 0.0
21082114
},
21092115
""Id"": 2
21102116
},
21112117
{
21122118
""Writer"": {
21132119
""FirstName"": ""firstNameWriter2"",
2114-
""LastName"": ""lastNameWriter2""
2120+
""LastName"": ""lastNameWriter2"",
2121+
""Alive"": false
21152122
},
21162123
""Reader"": {
21172124
""FirstName"": ""firstNameReader2"",
2118-
""LastName"": ""lastNameReader2""
2125+
""LastName"": ""lastNameReader2"",
2126+
""Alive"": false
21192127
},
21202128
""Host"": {
2121-
""HostName"": ""127.0.0.3""
2129+
""HostName"": ""127.0.0.3"",
2130+
""Rating"": 0.0
21222131
},
21232132
""Id"": 3
21242133
}
@@ -2145,16 +2154,19 @@ public virtual void Can_serialize_proxies_to_JSON()
21452154
""Writer"": {
21462155
""$id"": ""3"",
21472156
""FirstName"": ""firstNameWriter0"",
2148-
""LastName"": ""lastNameWriter0""
2157+
""LastName"": ""lastNameWriter0"",
2158+
""Alive"": false
21492159
},
21502160
""Reader"": {
21512161
""$id"": ""4"",
21522162
""FirstName"": ""firstNameReader0"",
2153-
""LastName"": ""lastNameReader0""
2163+
""LastName"": ""lastNameReader0"",
2164+
""Alive"": false
21542165
},
21552166
""Host"": {
21562167
""$id"": ""5"",
2157-
""HostName"": ""127.0.0.1""
2168+
""HostName"": ""127.0.0.1"",
2169+
""Rating"": 0
21582170
}
21592171
},
21602172
{
@@ -2163,16 +2175,19 @@ public virtual void Can_serialize_proxies_to_JSON()
21632175
""Writer"": {
21642176
""$id"": ""7"",
21652177
""FirstName"": ""firstNameWriter1"",
2166-
""LastName"": ""lastNameWriter1""
2178+
""LastName"": ""lastNameWriter1"",
2179+
""Alive"": false
21672180
},
21682181
""Reader"": {
21692182
""$id"": ""8"",
21702183
""FirstName"": ""firstNameReader1"",
2171-
""LastName"": ""lastNameReader1""
2184+
""LastName"": ""lastNameReader1"",
2185+
""Alive"": false
21722186
},
21732187
""Host"": {
21742188
""$id"": ""9"",
2175-
""HostName"": ""127.0.0.2""
2189+
""HostName"": ""127.0.0.2"",
2190+
""Rating"": 0
21762191
}
21772192
},
21782193
{
@@ -2181,16 +2196,19 @@ public virtual void Can_serialize_proxies_to_JSON()
21812196
""Writer"": {
21822197
""$id"": ""11"",
21832198
""FirstName"": ""firstNameWriter2"",
2184-
""LastName"": ""lastNameWriter2""
2199+
""LastName"": ""lastNameWriter2"",
2200+
""Alive"": false
21852201
},
21862202
""Reader"": {
21872203
""$id"": ""12"",
21882204
""FirstName"": ""firstNameReader2"",
2189-
""LastName"": ""lastNameReader2""
2205+
""LastName"": ""lastNameReader2"",
2206+
""Alive"": false
21902207
},
21912208
""Host"": {
21922209
""$id"": ""13"",
2193-
""HostName"": ""127.0.0.3""
2210+
""HostName"": ""127.0.0.3"",
2211+
""Rating"": 0
21942212
}
21952213
}
21962214
]
@@ -2634,6 +2652,7 @@ public class Person
26342652
{
26352653
public string FirstName { get; set; }
26362654
public string LastName { get; set; }
2655+
public bool Alive { get; set; }
26372656
}
26382657

26392658
public class Entity
@@ -2658,6 +2677,7 @@ public class Parson : Entity
26582677
public class Host
26592678
{
26602679
public string HostName { get; set; }
2680+
public double Rating { get; set; }
26612681
}
26622682

26632683
public abstract class Tribe
@@ -2746,6 +2766,7 @@ public class OwnedAddress
27462766
{
27472767
public string Street { get; set; }
27482768
public string PostalCode { get; set; }
2769+
public int CountryCode { get; set; }
27492770
}
27502771

27512772
protected DbContext CreateContext(bool lazyLoadingEnabled = false)

test/EFCore.Specification.Tests/TestModels/ChangedChangingMonsterContext.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,16 @@ public virtual IComputerDetail ComputerDetail
304304

305305
public class ConcurrencyInfo : NotificationEntity, IConcurrencyInfo
306306
{
307+
private bool _active;
307308
private string _token;
308309
private DateTime? _queriedDateTime;
309310

311+
public bool Active
312+
{
313+
get => _active;
314+
set => SetWithNotify(value, ref _active);
315+
}
316+
310317
public string Token
311318
{
312319
get => _token;

test/EFCore.Specification.Tests/TestModels/ChangedOnlyMonsterContext.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,16 @@ public virtual IComputerDetail ComputerDetail
299299

300300
public class ConcurrencyInfo : NotificationEntity, IConcurrencyInfo
301301
{
302+
private bool _active;
302303
private string _token;
303304
private DateTime? _queriedDateTime;
304305

306+
public bool Active
307+
{
308+
get => _active;
309+
set => SetWithNotify(value, ref _active);
310+
}
311+
305312
public string Token
306313
{
307314
get => _token;

test/EFCore.Specification.Tests/TestModels/MonsterModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public interface IComputer
6262

6363
public interface IConcurrencyInfo
6464
{
65+
bool Active { get; set; }
6566
string Token { get; set; }
6667
DateTime? QueriedDateTime { get; set; }
6768
}

test/EFCore.Specification.Tests/TestModels/SnapshotMonsterContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public class Computer : IComputer
107107

108108
public class ConcurrencyInfo : IConcurrencyInfo
109109
{
110+
public bool Active { get; set; }
110111
public string Token { get; set; }
111112
public DateTime? QueriedDateTime { get; set; }
112113
}

0 commit comments

Comments
 (0)