Im building a book library which handles Books and Journals.
I have a winform where the user enters some parameters to search on the library DB. i do not know which value he selects to insert.
For example:
public abstract class Item : IComparer, IEnumerable
{
public string Name { get; set; }
public string Publisher { get; set; }
public double Price { get; set; }
public double Discount { get; set; }
public DateTime ReleaseDate { get; set; }
}
this is my base class. when a user can insert to search by name (which translates into book name).
the UI has many options to search by, and basiclly includes almost all of the fields that a book contains.
What i need to do is filter out only the fields that the user inserted, pass them to my DAL so he can perform the search using a LINQ query on ENTITY framework mapped DB.
this is my search so far:
public List<Books> SelectBookFromDB(Item itemType)
{
BookVO book = itemType as BookVO;
var result = myEntities.Books.Where(x =>
x.Author == book.Author &&
x.Discount == book.Discount &&
x.Name == book.Name &&
x.Publisher == book.Publisher).ToList();
return result;
}
problem is, im searching for some values that may be null. that way, my searches always come up empty :(
i have no clue how to proceed. would love some help.
thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…