another option instead using AsEnumerable() in linq EF, when using custom method in linq
I have below code
class Program
{
static void Main(string[] args)
{
string keyword = "m";
using (TestingEntities1 db = new TestingEntities1())
{
var models = db.Teachers.AsEnumerable().Where(a => RemoveA(a.Name).Contains(keyword));
foreach (var item in models)
{
Console.WriteLine(item.Name);
}
}
}
static string RemoveA(string input)
{
return input.Replace('a', ' ');
}
}
as you can see in my code i must use AsEnumerable() to use custom function works because if i dont use i will get something error saus "LINQ to Entities does not recognize the method ' ' method, and this method cannot be translated into a store expression."
and then i ralized that asenumerable make slow becaseu i found that here How to improve AsEnumerable performance in EF says "you're doing is that you're downloading the whole BilBillMasters and BilBillDetails tables and then doing some processing on those in your application, rather than on the SQL server. This is bound to be slow." please see first anwer for more detail, So is there any way to make my code faster, my case i have more than one million data in my database