Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update exception messages for optional dependents #24602

Merged
1 commit merged into from
Apr 7, 2021
Merged
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/EFCore.Relational/Properties/RelationalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@
<comment>Debug RelationalEventId.ConnectionOpening string string</comment>
</data>
<data name="LogOptionalDependentWithoutIdentifyingProperty" xml:space="preserve">
<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>
<comment>Error RelationalEventId.ModelValidationOptionalDependentWithoutIdentifyingPropertyWarning string</comment>
<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>
<comment>Warning RelationalEventId.OptionalDependentWithoutIdentifyingPropertyWarning string</comment>
</data>
<data name="LogPossibleUnintendedUseOfEquals" xml:space="preserve">
<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>
Expand Down Expand Up @@ -680,7 +680,7 @@
<value>Expression '{sqlExpression}' in the SQL tree does not have a type mapping assigned.</value>
</data>
<data name="OptionalDependentWithDependentWithoutIdentifyingProperty" xml:space="preserve">
<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>
<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>
</data>
<data name="ParameterNotObjectArray" xml:space="preserve">
<value>Cannot use the value provided for parameter '{parameter}' because it isn't assignable to type object[].</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public virtual async Task Can_insert_dependent_with_just_one_parent()
context.Add(
new FuelTank
{
Capacity = "10000 l",
Capacity = 10000_1,
FuelType = "Gas",
VehicleName = "Fuel transport"
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public virtual void Passes_on_not_configured_shared_columns_with_shared_table()
}

[ConditionalFact]
public virtual void Throws_on_not_configured_shared_columns_with_shared_table()
public virtual void Throws_on_not_configured_shared_columns_with_shared_table_with_dependents()
{
var modelBuilder = CreateConventionalModelBuilder();

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

[ConditionalFact]
public virtual void Warns_on_not_configured_shared_columns_with_shared_table()
{
var modelBuilder = CreateConventionalModelBuilder();

modelBuilder.Entity<Owner>().OwnsOne(e => e.Owned);

var definition = RelationalResources.LogOptionalDependentWithoutIdentifyingProperty(new TestLogger<TestRelationalLoggingDefinitions>());
VerifyWarning(definition.GenerateMessage(nameof(OwnedEntity)), modelBuilder.Model);
}

[ConditionalFact]
public virtual void Detects_incompatible_shared_columns_with_shared_table()
{
Expand Down Expand Up @@ -2000,6 +2011,17 @@ protected class Employee : Person
{
}

protected class Owner
{
public int Id { get; set; }
public OwnedEntity Owned { get; set; }
}

protected class OwnedEntity
{
public string Value { get; set; }
}

public class TestDecimalToLongConverter : ValueConverter<decimal, long>
{
private static readonly Expression<Func<decimal, long>> convertToProviderExpression = d => (long)(d * 100);
Expand Down
2 changes: 2 additions & 0 deletions test/EFCore.Specification.Tests/DataAnnotationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,7 @@ public class StreetAddress
{
public string Street { get; set; }
public string City { get; set; }
public int ZipCode { get; set; }
}

public class Order
Expand Down Expand Up @@ -2630,6 +2631,7 @@ protected class Two
[Owned]
protected class Details
{
public int Value { get; set; }
public string Name { get; set; }
}

Expand Down
57 changes: 39 additions & 18 deletions test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2083,42 +2083,51 @@ public virtual void Can_serialize_proxies_to_JSON()
{
""Writer"": {
""FirstName"": ""firstNameWriter0"",
""LastName"": ""lastNameWriter0""
""LastName"": ""lastNameWriter0"",
""Alive"": false
},
""Reader"": {
""FirstName"": ""firstNameReader0"",
""LastName"": ""lastNameReader0""
""LastName"": ""lastNameReader0"",
""Alive"": false
},
""Host"": {
""HostName"": ""127.0.0.1""
""HostName"": ""127.0.0.1"",
""Rating"": 0.0
},
""Id"": 1
},
{
""Writer"": {
""FirstName"": ""firstNameWriter1"",
""LastName"": ""lastNameWriter1""
""LastName"": ""lastNameWriter1"",
""Alive"": false
},
""Reader"": {
""FirstName"": ""firstNameReader1"",
""LastName"": ""lastNameReader1""
""LastName"": ""lastNameReader1"",
""Alive"": false
},
""Host"": {
""HostName"": ""127.0.0.2""
""HostName"": ""127.0.0.2"",
""Rating"": 0.0
},
""Id"": 2
},
{
""Writer"": {
""FirstName"": ""firstNameWriter2"",
""LastName"": ""lastNameWriter2""
""LastName"": ""lastNameWriter2"",
""Alive"": false
},
""Reader"": {
""FirstName"": ""firstNameReader2"",
""LastName"": ""lastNameReader2""
""LastName"": ""lastNameReader2"",
""Alive"": false
},
""Host"": {
""HostName"": ""127.0.0.3""
""HostName"": ""127.0.0.3"",
""Rating"": 0.0
},
""Id"": 3
}
Expand All @@ -2145,16 +2154,19 @@ public virtual void Can_serialize_proxies_to_JSON()
""Writer"": {
""$id"": ""3"",
""FirstName"": ""firstNameWriter0"",
""LastName"": ""lastNameWriter0""
""LastName"": ""lastNameWriter0"",
""Alive"": false
},
""Reader"": {
""$id"": ""4"",
""FirstName"": ""firstNameReader0"",
""LastName"": ""lastNameReader0""
""LastName"": ""lastNameReader0"",
""Alive"": false
},
""Host"": {
""$id"": ""5"",
""HostName"": ""127.0.0.1""
""HostName"": ""127.0.0.1"",
""Rating"": 0
}
},
{
Expand All @@ -2163,16 +2175,19 @@ public virtual void Can_serialize_proxies_to_JSON()
""Writer"": {
""$id"": ""7"",
""FirstName"": ""firstNameWriter1"",
""LastName"": ""lastNameWriter1""
""LastName"": ""lastNameWriter1"",
""Alive"": false
},
""Reader"": {
""$id"": ""8"",
""FirstName"": ""firstNameReader1"",
""LastName"": ""lastNameReader1""
""LastName"": ""lastNameReader1"",
""Alive"": false
},
""Host"": {
""$id"": ""9"",
""HostName"": ""127.0.0.2""
""HostName"": ""127.0.0.2"",
""Rating"": 0
}
},
{
Expand All @@ -2181,16 +2196,19 @@ public virtual void Can_serialize_proxies_to_JSON()
""Writer"": {
""$id"": ""11"",
""FirstName"": ""firstNameWriter2"",
""LastName"": ""lastNameWriter2""
""LastName"": ""lastNameWriter2"",
""Alive"": false
},
""Reader"": {
""$id"": ""12"",
""FirstName"": ""firstNameReader2"",
""LastName"": ""lastNameReader2""
""LastName"": ""lastNameReader2"",
""Alive"": false
},
""Host"": {
""$id"": ""13"",
""HostName"": ""127.0.0.3""
""HostName"": ""127.0.0.3"",
""Rating"": 0
}
}
]
Expand Down Expand Up @@ -2634,6 +2652,7 @@ public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public bool Alive { get; set; }
}

public class Entity
Expand All @@ -2658,6 +2677,7 @@ public class Parson : Entity
public class Host
{
public string HostName { get; set; }
public double Rating { get; set; }
}

public abstract class Tribe
Expand Down Expand Up @@ -2746,6 +2766,7 @@ public class OwnedAddress
{
public string Street { get; set; }
public string PostalCode { get; set; }
public int CountryCode { get; set; }
}

protected DbContext CreateContext(bool lazyLoadingEnabled = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,16 @@ public virtual IComputerDetail ComputerDetail

public class ConcurrencyInfo : NotificationEntity, IConcurrencyInfo
{
private bool _active;
private string _token;
private DateTime? _queriedDateTime;

public bool Active
{
get => _active;
set => SetWithNotify(value, ref _active);
}

public string Token
{
get => _token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,16 @@ public virtual IComputerDetail ComputerDetail

public class ConcurrencyInfo : NotificationEntity, IConcurrencyInfo
{
private bool _active;
private string _token;
private DateTime? _queriedDateTime;

public bool Active
{
get => _active;
set => SetWithNotify(value, ref _active);
}

public string Token
{
get => _token;
Expand Down
1 change: 1 addition & 0 deletions test/EFCore.Specification.Tests/TestModels/MonsterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public interface IComputer

public interface IConcurrencyInfo
{
bool Active { get; set; }
string Token { get; set; }
DateTime? QueriedDateTime { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class Computer : IComputer

public class ConcurrencyInfo : IConcurrencyInfo
{
public bool Active { get; set; }
public string Token { get; set; }
public DateTime? QueriedDateTime { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class FuelTank
{
public string VehicleName { get; set; }
public string FuelType { get; set; }
public string Capacity { get; set; }
public int Capacity { get; set; }

public PoweredVehicle Vehicle { get; set; }
public CombustionEngine Engine { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ public class OperatorDetails
{
public string VehicleName { get; set; }
public string Type { get; set; }
public bool Active { get; set; }

public override bool Equals(object obj)
=> obj is OperatorDetails other
&& VehicleName == other.VehicleName
&& Type == other.Type;
&& Type == other.Type
&& Active == other.Active;

public override int GetHashCode()
=> HashCode.Combine(VehicleName, Type);
=> HashCode.Combine(VehicleName, Type, Active);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected IEnumerable<Vehicle> CreateVehicles()
FuelTank = new FuelTank
{
FuelType = "Liquid oxygen and anhydrous ammonia",
Capacity = "11250 kg",
Capacity = 11250,
VehicleName = "North American X-15A-2"
},
VehicleName = "North American X-15A-2"
Expand All @@ -168,7 +168,7 @@ protected IEnumerable<Vehicle> CreateVehicles()
FuelTank = new SolidFuelTank
{
FuelType = "Reduced smoke Hydroxyl-Terminated Polybutadiene",
Capacity = "22 kg",
Capacity = 22,
GrainGeometry = "Cylindrical",
VehicleName = "AIM-9M Sidewinder"
},
Expand Down
Loading