I am creating a C# service that will be doing some specialized processing of data coming into our ODS (Operational Data Store) DB. To support this, I’m building a DAL that will be used to access our ODS. In my DAL, I’ll have a number of GetItem (get a single item) and GetList (get a list of items) methods with a number of overrides to support a number of combinations of parameters for each method.
I was think that instead of having a number of overrides, I would do the following, using GetList as an example, using an Expression as the only parameter:
/// <summary> /// Gets a list of Marker entities based on a predicate. /// </summary> /// <param name="predicate">The predicate</param> /// <returns>List of Marker entities</returns> public List<Entities.Marker> GetList(Expression<Func<MarkerRecord, bool>> predicate) { return this.Database.Marker.Where(predicate).Map(); } And it would be called like this:
MarkerData markerData = new MarkerData(); var markerList = markerData.GetList(row => row.ReadTime >= new DateTime(2012, 1, 7)); I could even modify this to make it generic to handle any data type. While this solution offers flexibility and saves some coding, something tells me I'm violating one or more best practices, perhaps like separation of concerns by passing code as data. Do you see any problems with this approach?
IQueryable<>, to allow chaining. \$\endgroup\$