How to convert a native SQL query result to AsExpandable()? is this possible? RRS feed

  • Question

  • User-1651604128 posted


    I have a mvc web app with a filter (search) form, the Filter button contains  a complicated native SQL query such as this:


    //the method of controller below needs to return PagedList<tbl_Product> and call SelectRows
    return new PagedList<tbl_Product>(SelectRows(button, txtFilter1,  txtFilter2,  txtFilter3, txtFilter4);
     private IQueryable<tbl_Product> SelectRows(string txtFilter1, string txtFilter2, string txtFilter3, string txtFilter4,,,,)
    string strSQL = "Select * from tbl_Product where ......." 
    var SearchResultData = db.Database.SqlQuery<tbl_Product>(strSQL).ToList();
    //now, I need to return the above SearchResultData to IQuerable as below,
    return db.tbl_Product.AsExpandable().Where(SearchResultData); //but this is not compatable, 

    Is that possible to make it working? thanks a lot,

    Monday, July 29, 2019 1:28 PM

All replies

  • User-474980206 posted
    The AsExpandable() allows passing functions that return an expression tree, that is convertible to sql. Your example you are passing a List<>, not an expression tree. See this explanation:


    Monday, July 29, 2019 2:19 PM