Error when working with EF Core entities that use a ValueConverter
Hi
Premise:
I have a situation where I'm using a ValueConverter to map a property with a complex type to a simple string in the database.
This is how my entity looks:
public class MyEntity {
public List<Foo> Foos {get; set;}
//other fields
}
in my EF Core configuration, I specify that that particular property uses a converter:
modelBuilder.Entity<MyEntity >()
.Property(x => x.Foos)
.HasConversion<FooListConverter>();
The converter looks like this:
public class FooListConverter: ValueConverter<List<Foo>, string>{
//conversion implementation
}
so, as you can see, it converts the List<Foo> to a simple string, so it can be stored directly in the database.
The problem:
I'm trying to use Detached-Mapper to update an entity of type MyEntity, like this:
dbContext.Map<MyEntity>(entityDto);
however, this call is throwing the following exception:
An error was generated for warning 'Microsoft.EntityFrameworkCore.Query.InvalidIncludePathError': Unable to find navigation 'Foos' specified in string based include path 'MyEntity.Foos'. This exception can be suppressed or logged by passing event ID 'CoreEventId.InvalidIncludePathError' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
I'm a bit ignorant on this subject, so I may be completely wrong here, but I think Detached-Mapper is trying to treat the Foos property as a navigation property (a relationship). However, this is not a relationship, it is a simple field that is mapped directly to a DB column by converting it to a string (thanks to the ValueConverter).
I tried to mark the Foos property with the [Composition] attribute, and in that case I get past that error, however the problem is that now I get the same error for each property with a complex type inside the Foo object, because Detached is trying to go down and map everything inside the object (since it is marked as Composition). I haven't tested if marking every complex type inside Foo and its children as [Composition] fixes the problem, because some types inside it are from an assembly that doesn't reference Detached, so I cannot apply the attribute to their properties. However, even if it works it would just be a workaround and probably not the correct approach.
I think the "proper" solution would be for Detach to not treat properties that have a custom converter as navigation properties, if it is possible to do so automatically. Alternatively, maybe there is a way that I don't know to mark a property so it is treated as a "simple" (directly mappable to db) value and ignored? Can anyone help me out?
Thanks in advance for any support you can give me, and for your work on the library, it's awesome.