【发布时间】:2012-03-05 14:07:12
【问题描述】:
我正在使用具有以下定义的 EF:
public class StoredFile
{
public int StoredFileId { get; set; }
public HashCode HashCode { get; set; }
public string LocalName { get; set; }
//and some more fields here...
}
和
[ComplexType]
public class HashCode
{
public Byte [] ValueArr {get; set;}
public override bool Equals(object o) {...}
//some more methods to manipulate hash codes
}
我正在尝试使以下查询起作用:
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;
}
但是我得到“无法创建类型的常量值...”异常。我猜 LINQ 找不到上述 WHERE 语句的 SQL 翻译。
我知道以下问题:Entity Framework - "Unable to create a constant value of type..." exception,以及 Microsoft 的以下页面:Known Issues and Considerations in LINQ to Entities。但是,我仍然想根据其哈希码从我的数据库中选择一个文件。
谢谢,
编辑:我应该超越 L2E 限制。这个thread 有一些很好的指针和链接。
【问题讨论】:
标签: c# linq entity-framework-4