b.Query Object Pattern

  1. Motivation

      1. An object that represents a database query and can automatically generate queries on the fly based on context supplied.

  2. Summary

      1. A Query Object is an interpreter, that is, a structure of objects that can form itself into a SQL query. You can create this query by referring object context like classes and fields rather than tables and columns.

      2. This makes queries independent of the database schema and changes to the schema can be localized in a single place.

      3. it is usually uses Metadata Mapping pattern to generate actual database queries.

  1. When to Use

      1. Query Objects are a pretty sophisticated pattern to put together, so most projects don't use them if they have a handbuilt data source layer.

    1. ORM Frameworks like EF provide this feature out of the box and must be preferred over handcrafting

  1. References