You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exception occured when map single object from EF Core entity class (with proxy) #1024
Hi, i'm using Mapster ver. 10.0.11, i got exception when doing single object mapping The following members of destination class CreateApiRequest do not have a corresponding source member mapped or ignored: ...
which i have include described field in mapster config and passed TypeAdapterConfig.GlobalSettings.Compile();.
My code when call adapt: var entity = getEntityById(id); //EF Core entity var mapped = entity.Adapt<CreateApiRequest>(); //map with mapster, got exception here, compile is ok
As i investigated, it turns out that entity type is Proxy rather than actual type (i'm using EF LazyLoadingProxies).
Current workaround that i'm using is to specify source type when mapping: var mapped = entity.Adapt<EntityType, CreateApiRequest>(); //this line successfully run
Hi, @joko1189.
This is expected behavior. Mapster always returns a mapping function for the types you request (or declared of members within the Type).
The method .Adapt<CreateApiRequest>() in question is essentially a helper for in cases where the source type needs to be determined at runtime.
Note
.Adapt<CreateApiRequest>() is equal .Adapt<object,CreateApiRequest>() which is a meaningless operation, since an actual instance of type object cannot have state that could be passed during mapping 😅.
For this reason, the specified method performs two actions simultaneously:
Determines the actual (runtime) type of the source variable;
Requests a mapping function from the actual (runtime) type to the Destination type.
As i investigated, it turns out that entity type is Proxy rather than actual type (i'm using EF LazyLoadingProxies).
You most likely set the following value somewhere in the configuration: TypeAdapterConfig.GlobalSettings.AllowImplicitSourceInheritance = false;
default state is: TypeAdapterConfig.GlobalSettings.AllowImplicitSourceInheritance = true;
For this reason, an automatically created proxy source type is prohibited inheriting configuration from its parent type, and you receive the error you mentioned.
[TestMethod]
public void ProxySourceTypeInheritanceBaseSourceSettings()
{
TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = true;
TypeAdapterConfig.GlobalSettings.AllowImplicitSourceInheritance = false; // comment or set to true
TypeAdapterConfig<SimplePoco, SimpleDto>
.NewConfig()
.Ignore(x => x.IgnoreData)
.Compile();
var proxy = new SimplePocoProxy() { Id = Guid.NewGuid(), Name = "Hello" };
var result = proxy.Adapt<SimpleDto>(); // exception if AllowImplicitSourceInheritance = false; no exception if AllowImplicitSourceInheritance = true
}
Activity
DocSvartz commentedon Oct 12, 2026
Hi, @joko1189.
This is expected behavior. Mapster always returns a mapping function for the types you request (or declared of members within the Type).
The method
.Adapt<CreateApiRequest>()in question is essentially a helper for in cases where the source type needs to be determined at runtime.Note
.Adapt<CreateApiRequest>()is equal.Adapt<object,CreateApiRequest>()which is a meaningless operation, since an actual instance of typeobjectcannot have state that could be passed during mapping 😅.For this reason, the specified method performs two actions simultaneously:
You most likely set the following value somewhere in the configuration:
TypeAdapterConfig.GlobalSettings.AllowImplicitSourceInheritance = false;default state is:
TypeAdapterConfig.GlobalSettings.AllowImplicitSourceInheritance = true;For this reason, an automatically created proxy source type is prohibited inheriting configuration from its parent type, and you receive the error you mentioned.