I am playing with a basic implementation of the Query Object "pattern" (in quotes since this is an implementation of the interpreter pattern), and I was thinking of an enhancement which I do not know how to implement.
As you know a Criterion object would look something like the following:
public class Criterion
{
...
string FieldName { get; set; }
string Value { get; set; }
....
}
What I do not like is the fact that I have to add the field a string so I was thinking if I could create some kind of generic Criterion class so I could use it like so:
var criterion = new Criterion<Person>();
criterion.Field = c => c.FirstName;
criterion.Value = "John";
or something along those lines.
Of course there also would be the part where the criteria needs to be converted into SQL so I could do something like:
string query = "SELECT * FROM Person WHERE " + criteria.Field.ToString() + " = '" + criteria.Value + "'"
I am sure there's got to be a way of doing this but I just can't wrap my head around it.
Thanks for your help.