投与linqToEntity(ESQL)
问题描述:
我的代码:投与linqToEntity(ESQL)
public List<Book> GetBook(string NameField, object Value)
{
var queryESQL = @"select VALUE Book from Book
where Cast(Book." + NameField + " as string) like '%M%'";
var query = this.Entities.CreateQuery<Book>(
queryESQL);
return query.ToList();
}
错误:
类型 '串' 无法找到。确保加载了所需的模式 ,并且正确导入了名称空间。近类型 名,行2,列51
更新:
新代码:
public List<Book> GetBook(string NameField, object Value)
{
var queryESQL = @"select VALUE Book from Book
where Cast(Book." + NameField + " as EDM.string) like '%M%'";
var query = this.Entities.CreateQuery<Book>(
queryESQL);
return query.ToList();
}
错误:
Type 'EDM.string' could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly. Near type name, line 2, column 51.
答
使用Edm.String
而不是string
时铸件。
答
CreateQuery<>
方法使用CLR类型而不是EDM类型,因此在查询中使用System.String
而不是EDM.String
。
+0
这对我有用。谢谢。虽然我不明白为什么Edm.String不起作用 –
错误:无法找到类型'EDM.string'。确保已加载所需的模式并正确导入名称空间。靠近类型名称,第2行,第51列。 – mrJack
@mrJack:你确定在'EDM.String'中大写了'S'吗? – StriplingWarrior
@StriplingWarrior:是的,我相信 – mrJack