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.

naveen vadla7 reputationPosted Feb 13, 2023, 12:14 PM EST
using System; using System.Data; using System.Data.SqlClient; using DocumentFormat.OpenXml; using Excel = Microsoft.Office.Interop.Excel; namespace projectdemosql { class Program { public static void GetData() { SqlConnection con = new SqlConnection("Data Source=LAPTOP-C66D0I8E\\SQLEXPRESS;Initial Catalog=demoproject;Persist Security Info=True;User ID=sa;Password=navya1920"); SqlCommand cmd = new SqlCommand("select * from college", con); SqlDataAdapter da=new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds,"tbdata"); var excelApp = new Excel.Application(); excelApp.Workbooks.Add(); // single worksheet Excel._Worksheet workSheet = excelApp.ActiveSheet; // column headings for (var i = 0; i /// The main entry point for the application. /// static void Main() { GetData(); } } }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
Tuhin PaulRank #7 · 71.9K reputationPosted Feb 14, 2023, 4:07 AM EST
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:MapperConfiguration _config = new MapperConfiguration(cfg => { cfg.CreateMap(); cfg.CreateMap>, Expression>>(); });This should allow AutoMapper to convert the expression parameter correctly when you call
_Mapper.Map.