Rush.2707 Rush.2707 - 2 months ago 32
C# Question

linq query to search from 5 arrays

I am getting five arrays from client side, and I have five lists from which I have to show values of that rows of the database that are selected by client(which are i am getting in array). I need a LINQ query through which I can select rows from database for particular values. Here it is my controller to write query.
Please guide me how to do this i am new to this all.

[HttpPost]
public ActionResult somemethod(string[] array1, string[] array2, string[] array3, string[] array4, string[] array5)
{
List<string> results = objUS.tablename.Select(q => q.colname).ToList();
var USData = (from row in objUS.tablename where (row.is_deleted == false)
select row);
if (!string.IsNullOrEmpty(array1[0]))
{
for (var item = 0; item < array1.Length; item++)
{
USData.Where(x => results.Contains(array1[item]));
}
}
return View(USData);
}


I am getting some errors there. I have tried for one field only yet. Please guide me to do this.

I get colname's data in array. I got 5 different fields and I get data of anyone's from client. Now the thing is i need to filter or search rows from database where appropriate colname's data from database.

Answer

It can be done by this partialview

[HttpPost]
    public ActionResult AR(IList<string> array, IList<string> array, IList<string> array, IList<string> array, IList<string> array)
    {
        array[0] = array[0].ToString();
        array[0] = array[0].ToString();
        array[0] = array[0].ToString();
        array[0] = array[0].ToString();
        array[0] = array[0].ToString();

        int tempR = Convert.ToInt32(Session["ID"]);

        var USData = objUS.tableName.Where(u => u.colName == false);

        if (array.Count < 2 && array.Count < 2 && array.Count < 2 && array.Count < 2 && array.Count < 2)
        {
            function2(Convert.ToInt32(Session["ID"]));
        }

        if (array1.Count > 1)
            USData = USData.Where(u => array1.Contains(u.tableName.colName));

        if (array2.Count > 1)
            USData = USData.Where(u => array2.Contains(u.tablename.colName));

        if (array3.Count > 1)
            USData = USData.Where(u => array3.Contains(u.tablename.colName));

        if (array4.Count > 1)
            USData = USData.Where(u => array4.Contains(u.tablename.colname));

        if (array5.Count > 1)
            USData = USData.Where(u => array5.Contains(u.tablename.tablename.colName));
        if (tempR != 0)
        {
            if (tempR != 1)
                USData = USData.Where(us => us.colName == tempR);
            else
                USData = USData.Where(us => us.colName == null);
        }
        ViewBag.RecordCount = recordCount = USData.Count();
        return PartialView("functionName", USData);
    }
Comments