I'd like to make a query to my SQL Server 2008 R2 database using Linq-To-Entities.
I use Entity Framework 4.1 (Code-First)
the query has to compare the entities' hashed values with a paramater as follows:
myContext.Messages.Where(m => HashCode(m.MessageId) % 10000 == myValue)
But I can only use core extension methods and CLR methods defined for the EF provider.
So I'm trying to translate my HashCode()
method to something that L2E understands just before execution.
FYI, HashCode's implementation is not complex. something like:
public int HashString(string text)
{
int hash = 23;
foreach (char c in text)
{
hash = hash * 31 + c;
}
return hash;
}
I know I can retrieve all the entities as enumerable and check them in my code (Linq To Objects), But that's be a disaster considering the amount of data I'm about to retrieve that way.
Is it doable at all (for GetHashCode
method). If so, how can I implement it?
Thank you.