I am trying to search the object from its list using entity framework.
I have following structure of the object
public class Product
{
public int Id { get; set; }
public string ProductName { get; set; }
public double Size { get; set; }
}
and I create the list of the product
private List<Product> AddProducts()
{
List<Product> ProductList = new List<Product>();
oProduct Product = new Product();
oProduct.Id = 1;
oInventory.ProductName = "Product1";
oProduct.Size = 25;
ProductList.Add(oProduct);
oProduct Product = new Product();
oProduct.Id = 2;
oInventory.ProductName = "Product2";
oProduct.Size = 25;
ProductList.Add(oProduct);
return ProductList;
}
Now, I am trying to search the object form the above list form ProductName parameter.
I have used below code.
public ActionResult Index(string productname = "", string size = "")
{
var oProdList = from ProdList in AddProducts() select oProdList;
oProdList = oProdList.Where(oProd => oProd.ProductName.ToUpper().Contains(ProductName.ToUpper().Trim())|| oProd.Size.ToString().ToUpper().Contains(size.ToUpper().Trim()));
ViewBag.ProductList = oProdList;
return View();
}
Now Please check picture below, I have list of products and I am trying to find the Product1 by typing it in text box and I keep the size textbox blank. now when I click on submit , I pass these two varibles for searching in Index method (above one) but the LINQ command returns the both records, Product1 and Product 2 but it should return only one record
How to deal with this ?
