I am using EF with the following definitions:
public class StoredFile
{
public int StoredFileId { get; set; }
public HashCode HashCode { get; set; }
public string LocalName { get; set; }
//and some more fields here...
}
and
[ComplexType]
public class HashCode
{
public Byte [] ValueArr {get; set;}
public override bool Equals(object o) {...}
//some more methods to manipulate hash codes
}
I am trying to get the following query to work:
public bool TryGetFileInfo(MachineSafeDbDataContext dataContext, HashCode hash, out StoredFile fileInfo)
{
var matches = from curr in dataContext.StoredFiles where (hash.Equals(curr.HashCode)) select curr;
if (matches.Count() == 0)
{
fileInfo = null;
return false;
}
fileInfo = matches.First();
return true;
}
However I get the "Unable to create a constant value of type ..." exception. I guess LINQ fails to find a translation to SQL for the above WHERE statement.
I am aware of the following question: Entity Framework - "Unable to create a constant value of type..." exception, and of the following page by Microsoft: Known Issues and Considerations in LINQ to Entities. However, I would still like to select a file from my DB based on its hash code.
Thanks,
Edit: I should have gone over L2E limitations. This thread has some good pointers and links.