2013-08-16 213 views
0

我正在使用petapoco。並使搜索查詢像mvc4 PetaPoco像查詢拋出異常

請讓我知道有沒有正確的查詢?

var context = new PetaPoco.Database(Connection.connectionstring); 

      SqlQuery = 

      @"SELECT MenuId, MenuTitle, OrderNumber, CreatedDate, IsActive 
      from Menu 
      where MenuTitle LIKE @0, '%@MenuTitle%'"; 

      List<MenuPOCO> objMenuPoco = context.Query<MenuPOCO> 
       (
       SqlQuery, 
       new 
       { 
        @MenuTitle = MenuTitle 

       }).ToList(); 

      return objMenuPoco; 

請讓我知道語法是正確的?我在每次搜索中獲得0條記錄。

問候

+0

好現在得到。正確的是:List objMenuPoco = context.Query (「SELECT * FROM Menu WHERE MenuTitle LIKE @ 0」,「%」+ MenuTitle +「%」)。ToList(); – dotnetexpert

回答

1
var context = new PetaPoco.Database(Connection.connectionstring); 

     SqlQuery = 

     @"SELECT MenuId, MenuTitle, OrderNumber, CreatedDate, IsActive 
     from Menu 
     where MenuTitle LIKE @0"; 

     List<MenuPOCO> objMenuPoco = context.Query<MenuPOCO>(SqlQuery, "%" + MenuTitle + "%").ToList(); 

     return objMenuPoco; 
+0

看到我想運行這一個實際的查詢:http://stackoverflow.com/questions/18402194/peta-poco-like-query-issue – dotnetexpert