Вопрос

Below is my method of searching using predicate builder there is no error showing in visual studio but the problem is that the below code is not executing.

public JsonResult GetSearchedGraph(string searchItem, string itemTypeEnum)
        {

            var pre = PredicateBuilder.True<Graph>();
           pre.And(m => m.isHidden == false && m.ItemType!="FOLDER");
            if (!String.IsNullOrEmpty(searchItem))
           {
               pre.And(m => m.GraphItemTitle.ToUpper().Contains(searchItem.ToUpper()));
            }
            if (!String.IsNullOrEmpty(itemTypeEnum))
            {
                pre.And(m => m.ItemType == itemTypeEnum);
            }

            var searchGraph = from m in db.Graphs.AsQueryable() select m;
           searchGraph = db.Graphs.Where(pre);

           return Json(searchGraph.ToList(), JsonRequestBehavior.AllowGet);
        }

I am not getting any search result by using this method what it is wrong with this code?

Это было полезно?

Решение

well, you just have to do correct assignments.

because pre.And() doesn't impact pre

var pre = PredicateBuilder.True<Graph>();
//assign result of pre.And(xxx) to pre
pre = pre.And(m => m.isHidden == false && m.ItemType!="FOLDER");
if (!String.IsNullOrEmpty(searchItem))
{
     //same
     pre = pre.And(m => m.GraphItemTitle.ToUpper().Contains(searchItem.ToUpper()));
}
if (!String.IsNullOrEmpty(itemTypeEnum))
{
    //same
    pre = pre.And(m => m.ItemType == itemTypeEnum);
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top