How to use replace method in entity framework. I use following code but encounter error.
using (SepasProjectEntities sp=new SepasProjectEntities())
{
var query = (from p in sp.HISAccidentLocationMappings
where p.Name.Replace('y','x').Contains(txt1.Text)
select p
).ToList();
}
An exception of type 'System.NotSupportedException' occurred in System.Data.Entity.dll but was not handled in user code
Additional information: LINQ to Entities does not recognize the method 'System.String Replace(Char, Char)' method, and this method cannot be translated into a store expression.
Based on this MSDN article that contains list of supported methods by Entity Framework - there is just one overload of Replace method that is supported, and it's
System.String Replace(String oldValue, String newValue)
And not
System.String Replace(char oldValue, char newValue)
that you are using. Try to replace it with string version from
Name.Replace('y','x')
to
Name.Replace("y","x")
I didn't try it, but based from documentation it should work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With