whats is wrong with this linq query?

后端 未结 1 700
南旧
南旧 2021-01-28 22:12

i have a product table which has a Title as string.

inside my view i have

    @using (Html.BeginForm(\"Serach\",\"Store\"))
        {

          

        
相关标签:
1条回答
  • 2021-01-28 22:50

    Well, you should use some logging to find out what's actually being sent to the database - but personally I'd split the query up before it gets there:

    public ActionResult Search(string q)
    {
        var result = string.IsNullOrEmpty(q) ? storeDB.Products
                         : storeDB.Products.Where(p => p.Title.Contains(q));
    
        return View(result);
    }
    

    It's possible that the SQL dialect supported by SQL CE doesn't support the check for emptiness that you were using - and this gets round that problem.

    0 讨论(0)
提交回复
热议问题