Peta POCO like query issue

2019-08-31 02:02发布

问题:

I am using Micro ORM PetaPOCO, and I want to use like query, i am getting exception, please help me if any one know.

var context = new PetaPoco.Database(Connection.connectionstring);
            SqlQuery = @"SELECT CmsPage.PageId, CmsPage.PageTitle, CmsPage.MenuId, CmsPage.PageDescription, CmsPage.Title, CmsPage.MetaKeyword, CmsPage.MetaDescription, CmsPage.CreatedDate, CmsPage.IsActive
            FROM ( SELECT ROW_NUMBER() OVER (ORDER BY CmsPage.PageTitle) AS row, CmsPage.PageId, CmsPage.PageTitle, CmsPage.MenuId, CmsPage.PageDescription,
            CmsPage.Title, CmsPage.MetaKeyword, CmsPage.MetaDescription, CmsPage.CreatedDate, CmsPage.IsActive FROM CmsPage ) AS CmsPage WHERE
            CmsPage.PageTitle LIKE @0 and row > ((@CurrPage - 1) * @PageSize)  and  row <= (@CurrPage * @PageSize)";


            List<CmsPagePOCO> obCmsPagePOco = context.Query<CmsPagePOCO>(
                SqlQuery, 
                    new 
                    {
                        @CurrPage = CurrPage,
                        @PageSize = PageSize,
                        @PageTitle = "%" + PageTitle + "%"

                    }).ToList();

            return obCmsPagePOco;

getting this exception :

No mapping exists from object type <>f__AnonymousType1`3[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] to a known managed provider native type.

回答1:

You are mixing @0 in the like with named parameters

change to:

CmsPage.PageTitle LIKE @PageTitle and row > ...