I have a .Net function that takes 3 parameters, all optional. Something like that:
public List<MyObject> Search(string colour, string size, string name) { var result = (from c in MyTable where .... select c).ToList(); }
My question is what is the best way to do the where part. Would it be best to create dynamic linq? What is the best model, within linq, to have an optional parameter?
So, in SQL, something like this:
SELECT * FROM MyTable WHERE (@colour <> '' AND colour = @colour) AND (@size <> '' AND size = @size) AND (@name <> '' AND name = @name)
But I hope that there will be a more accurate, more acceptable template for this in linq.
source share