Entity framework 使用linqToEntity(Esql)进行铸造
我的代码:Entity framework 使用linqToEntity(Esql)进行铸造,entity-framework,c#-4.0,entity-sql,Entity Framework,C# 4.0,Entity Sql,我的代码: 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
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();
}
铸造时使用
Edm.String
而不是String
。铸造时使用Edm.String
而不是String
。CreateQuery
方法使用CLR类型,而不是Edm类型,因此,在查询中使用System.String
而不是EDM.String
。CreateQuery
方法使用CLR类型而不是EDM类型,因此在查询中使用System.String
而不是EDM.String
。错误:找不到类型“EDM.String”。确保加载了所需的架构,并且正确导入了名称空间。在类型名称第2行第51列附近。@Jack先生:您确定在EDM.String
中将S
大写了吗?@StriplingWarrior:是的。我确定错误:找不到类型“EDM.String”。确保加载了所需的架构,并且正确导入了名称空间。靠近类型名称,第2行,第51列。@Jack先生:你确定你把EDM.String
中的S
大写了吗?@StriplingWarrior:是的。我确信这对我有用。谢谢虽然我不明白为什么Edm.String不起作用,但这对我来说很有效。谢谢虽然我不明白为什么Edm.String不能工作
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.