我有一个方法试图通过一个简单的 where 子句从我的数据库中提取记录。我有一个问题,因为我传递了一个字符串值并将其与 Guid (uniqueIdentifier) 匹配。我需要将传递的值作为字符串绑定(bind)到 DataGrid 中,并且我需要返回字符串的方法。
显然在运行时,LinQ 无法编译查询。 .ToString()
方法无法编译成 SQL。有什么想法吗?
private string getFileLocation(string LinkGuid)
{
try
{
ISESEntities context = new ISESEntities();
string query = (from f in context.tbFileAttachments
where f.CCCPGUID.ToString() == LinkGuid
select f.FileLocation).First();
return query;
}
catch(Exception e)
{
blah blah
}
}
最佳答案
切换逻辑并将 LinkGuid
参数转换为 Guid:
private string getFileLocation(string LinkGuid)
{
try
{
Guid search = Guid.Parse(LinkGuid);
ISESEntities context = new ISESEntities();
string query = (from f in context.tbFileAttachments
where f.CCCPGUID == search
select f.FileLocation).First();
return query;
}
catch(Exception e)
{
blah blah
}
}
关于c# - Linq 查询中的 Guid.ToString()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24556352/