1

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.
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
mrJack
  • 1,001
  • 6
  • 17
  • 33

2 Answers2

8

The CreateQuery<> method uses the CLR types, instead of EDM types, so use System.String instead of EDM.String in the query.

eeerahul
  • 1,629
  • 4
  • 27
  • 38
Aran
  • 81
  • 1
  • 1
2

Use Edm.String instead of string when casting.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670