Hi, I am working on an applicaition in which I am communicating Database via Generic Repository and UnitOfWork. In my service layer i have to convert my viewmodels to actual database models ,with the help of automapper, in order to get data from database. All is going well but I having issue when want to convert exression by automapper. It is converted but when in this method
public IQueryable
{
IQueryable
query = include.Aggregate(query, (current, inc) => current.Include(inc));
var result= query.Where(predicate).ToList();
return query.Where(predicate);
} t
this statement:
var result= query.Where(predicate).ToList();
try to execute it gives this error.
System.ArgumentException: 'ParameterExpression of type 'BusinessEntities.ProductEntity' cannot be used for delegate parameter of type 'DataModel.Data.tblProduct''
here is debug view after conversion
.Lambda #Lambda1
$x.Price > (System.Nullable`1[System.Decimal])((System.Decimal)0)
}
this is my mapping code
MapperConfiguration _config = new MapperConfiguration(cfg => cfg.CreateMap
IMapper _Mapper = _config.CreateMapper();
var exp = _Mapper.Map
How can I change delegate parameter to type tblProduct.
Thanks in advance.
Regards,
Asif Aziz.
Tuhin PaulPosted Feb 14, 2023, 9:07 AM
It looks like you are trying to pass an expression that references
ProductEntityto a method that expects an expression that referencestblProduct, and AutoMapper is not handling the conversion correctly. You can try updating your AutoMapper mapping configuration to include a mapping fromProductEntitytotblProduct, like this:This should allow AutoMapper to convert the expression parameter correctly when you call
_Mapper.Map.naveen vadlaPosted Feb 13, 2023, 5:14 PM
I am done this code soo need to related code mail send to excel code to use this code please send the code before check my code