1

我的代码:

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.
4

2 回答 2

8

CreateQuery<>方法使用 CLR 类型,而不是 EDM 类型,因此在查询中使用System.String而不是。EDM.String

于 2011-11-17T03:33:26.630 回答
2

施法时使用Edm.String代替。string

于 2011-08-25T08:28:33.493 回答