C# 不支持Single()方法
我正在windows azure项目中实现表存储。我的代码:C# 不支持Single()方法,c#,asp.net-mvc-3,C#,Asp.net Mvc 3,我正在windows azure项目中实现表存储。我的代码: /// //// Method of _Table class public CloudTableQuery<Html> AccessEntites() { CloudTableQuery<Html> entries = (from e in ServiceContext.CreateQuery<Html>(TableName)
/// //// Method of _Table class
public CloudTableQuery<Html> AccessEntites()
{
CloudTableQuery<Html> entries =
(from e in ServiceContext.CreateQuery<Html>(TableName)
select e).AsTableServiceQuery();
return entries;
}
/// //
/// Controller code
private _Table db = new _Table("table-name");
public ViewResult Details(string id)
{
Html htmlfile = db.AccessEntites().Single(h => h.RowKey == id); <=========
return View(htmlfile);
}
//////
////表类的方法
public CloudTableQuery访问项()
{
CloudTableQuery条目=
(来自ServiceContext.CreateQuery(TableName)中的e)
选择e).AsTableServiceQuery();
返回条目;
}
/// //
///控制器代码
私有表db=新表(“表名”);
公共视图结果详细信息(字符串id)
{
Html htmlfile=db.AccessEntites().Single(h=>h.RowKey==id);显然,azure表存储的LINQ提供程序不支持Single
方法,即它无法在运行时将其转换为适当的查询
使用FirstOrDefault
代替-使用System.Linq
是否有可能?这是什么\u表
和什么db.AccessEntites()
返回???Linq
和sql
不完全相同。不是所有可以用ling
描述的内容都可以自动转换为sql
。当你做了计算机无法翻译的事情时,你就会得到这条信息。(您可以用sql
替换您试图使用Linq
访问的任何数据提供程序)我也发布了AccessEntites()方法,各位,请仔细查看