Repository navigation
Description
Developing a provider for EF Core there is point obscure.
Starting from this simple model:
[Table("TaxInfo", Schema = "ComplexTest")]
public class TaxInfo
{
public int TaxInfoId { get; set; }
public char Code { get; set; }
public decimal Percentage { get; set; }
[Required]
public TaxInfoExtended TaxInfoExtended { get; set; }
[Required]
public TaxInfoExtended TaxInfoExtended2 { get; set; }
public int ExtraValue { get; set; }
}
[ComplexType]
public class TaxInfoExtended
{
public int CodeExtended { get; set; }
public decimal PercentageExtended { get; set; }
}currently the data are saved to manage this kind of condition, however the focus of the issue is related on how the complex type can be made available back.
The code is using the following API:
efcore/src/EFCore/Update/Internal/UpdateAdapter.cs
Lines 150 to 153 in 2628175
| public virtual IUpdateEntry CreateEntry( | |
| IDictionary<string, object?> values, | |
| IEntityType entityType) | |
| => _stateManager.CreateEntry(values, entityType); |
which accept in input a
IDictionary<string, object?> then the content is passed to the StateManager and used:
efcore/src/EFCore/ChangeTracking/Internal/StateManager.cs
Lines 275 to 282 in 2628175
| public virtual InternalEntityEntry CreateEntry(IDictionary<string, object?> values, IEntityType entityType) | |
| { | |
| var entry = new InternalEntityEntry(this, entityType, values, EntityMaterializerSource); | |
| UpdateReferenceMaps(entry, EntityState.Detached, null); | |
| return entry; | |
| } |
The InternalEntityEntry try to get the properties from the dictionary using the Name property of the flattened list:
efcore/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
Lines 69 to 85 in 2628175
| foreach (var property in entityType.GetFlattenedProperties()) | |
| { | |
| var index = property.GetIndex(); | |
| if (index < 0) | |
| { | |
| continue; | |
| } | |
| valuesArray[index] = values.TryGetValue(property.Name, out var value) | |
| ? value | |
| : property.Sentinel; | |
| } | |
| Entity = entityType.GetOrCreateMaterializer(entityMaterializerSource)( | |
| new MaterializationContext(new ValueBuffer(valuesArray), stateManager.Context)); | |
| } | |
however, from our test, the flattened list contains all properties, but the Name property of the IProperty does not distinguish between the same property of multiple ComplexType. In the above example how is it possible to fill in the dictionary to distinguish between CodeExtended of TaxInfoExtended and TaxInfoExtended2?
Or, despite from the usage of flattened list of properties in InternalEntityEntry, the dictionary shall be filled in only with the Entity properties and the complex one shall be set using the UpdateEntry class?
Activity
[-]Manage multiple properties using the same CompleType in IUpdateAdapter.CreateEntry[/-][+]Manage multiple properties using the same ComplexType in IUpdateAdapter.CreateEntry[/+]Add IUpdateAdapter.CreateEntry overload that works with non-collectio…
Add IUpdateAdapter.CreateEntry overload that works with non-collectio…
Add IUpdateAdapter.CreateEntry overload that works with non-collectio…