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

ConstructUsing not working when mapping to interfaces #65

Closed
Tip77 opened this issue Jun 15, 2016 · 0 comments
Closed

ConstructUsing not working when mapping to interfaces #65

Tip77 opened this issue Jun 15, 2016 · 0 comments

Comments

@Tip77
Copy link

Tip77 commented Jun 15, 2016

Mapping to interfaces seems not to work.
with
config.ForType<PBPatient, IPatient>() .ConstructUsing(src => new Patient());

I get the following error:

System.ArgumentException : Expression of type 'System.Linq.Expressions.Expression1[System.Func2[PBPatient,Business.Patient]]' cannot be used for parameter of type 'System.Linq.Expressions.Expression1[System.Func2[PBPatient,IPatient]]' of method 'System.Linq.IQueryable1[IPatient] Select[PBPatient,IPatient](System.Linq.IQueryable1[PBPatient], System.Linq.Expressions.Expression1[System.Func2[PBPatient,IPatient]])'
Result StackTrace:
at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0, Expression arg1)
at Mapster.TypeAdapterConfig.CreateProjectionCallExpression(TypeTuple tuple)
at Mapster.TypeAdapterConfig.Compile()

However if I use
config.ForType<PBPatient, IPatient>() .ConstructUsing(src => new Patient() as IPatient);

I get the following error:

System.InvalidOperationException : Input ConstructUsing is invalid for projection: TSource: PBPatient TDestination: IPatient

Is there a workaround to Support Interfaces?

@Tip77 Tip77 changed the title Map to interfaces ConstructUsing not working when mapping to interfaces Jun 16, 2016
kellyethridge pushed a commit to kellyethridge/Mapster that referenced this issue Oct 1, 2016
kellyethridge pushed a commit to kellyethridge/Mapster that referenced this issue Nov 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant