使用 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.
my code :
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();
}
error :
Type '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.
update :
new code :
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();
}
error :
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CreateQuery<>
方法使用 CLR 类型,而不是 EDM 类型,因此在查询中使用System.String
而不是EDM.String
。The
CreateQuery<>
method uses the CLR types, instead of EDM types, so useSystem.String
instead ofEDM.String
in the query.投射时使用
Edm.String
而不是string
。Use
Edm.String
instead ofstring
when casting.