mvc4 PetaPoco like query throwing exception

2019-09-04 11:58发布

问题:

I am using petapoco. and making search query with like

please let me know there is right query or not?

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;

please let me know the syntax is right? I am getting 0 records in each search.

Regards

回答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;