I am curious as to what the best practice is for performing queries that contain methods/functions not supported by Entity Framework with no SQL conversion.
For example:
DataContext db = new DataContext();
Administrator admin = db.Administrators.Where(admin => admin.Username.ToString() == "test");
Will not work as the method ToLower() has no supported SQL conversion.
Currently I do this:
DataContext db = new DataContext();
Administrator admin = db.Administrators.ToArray().Where(admin => admin.Username.ToString() == "test");
However I do not think converting the administrators set to an array to perform these kind of queries is very good performance wise.
Can someone please tell me what the best practice is for these kinds of queries in Entity Framework?
Thanks,
Alex.
Two choices –
ToArray()and then you can use all the methods you want (not great performance unless the initial result set is small).The Entity Framework query provider has to know how to translate the method call into SQL and while you can develop your own, I don’t think you can subclass theirs – so adding your own methods to it won’t be easy. Or, to put it another way, bloody difficult!
It’s probably horribly unpopular, but I’m still using a lot of SPs when I get to the real nitty-gritty of data querying. Although part of the motivation in my environment is whether other non-EF environments need to be able to reproduce similar behaviours.