You get this error because your LINQ to SQL does not recognize the ToString() method.
If you want to convert int to string , and you are using SQL Server with EF, use the SqlFunctions.StringConvert function this way:
let poid = SqlFunctions.StringConvert((double)po.PurchaseOrderID);
or this, as an alternative:
where Convert.ToString(po.PurchaseOrderID).Contains(term)
The problem is that we donβt know what provider you are using with EF. In the case of SQL Server, this will work, but if the provider is different, for example, MySQL using this expression, the application will throw an exception with this message:
The specified System.String StringConvert method of type 'System.Data.Objects.SqlClient.SqlFunctions' cannot be translated into a LINQ to Entities storage expression.
Be careful!
In case you are not using SQL Server as a provider, use an explicit cast to your query, as suggested by @SimonBelanger:
let poid = (string)po.PurchaseOrderID
source share