EF Core ToString() Method Causing Exception

So basically my code is breaking over below line

var saleOrderIds= saleOList.Select(saleOList => saleOList.SaleOrderId.ToString()).ToList();

At the above code following exception is occuring

comparisonType: CurrentCultureIgnoreCase))’ could not be translated. Additional information: Translation of the ‘string.Equals’ overload with a ‘StringComparison’ parameter is not supported.

The Same Line Was Working Fine In .Net Framework

How to resolve the issue , is there any alternate way to achieve the result in EfCore,.Net6 ?

>Solution :

var saleOrderIds= saleOList.Select(saleOList => saleOList.SaleOrderId).ToList().Select(x => x.ToString());

That said, I wonder if this is an x-y problem. Normally, converting integer primary keys into strings is a bad idea. Why are you doing that?

Leave a Reply