When a class inherits from DataObject like so:

public LineItem : DataObject<LineItem>
  public Guid LineItemId { get; set; }
  /* etc. */

It's automagically blessed with two methods.


As seen on the Home page, this method is added statically to child DataObject classes and lets us select records with minimal effort or knowledge of class relationships at query time.

For example:

var lines = LineItem.Get(new LineItem() {
  OrderId = new Guid("{622E2962-2E91-4105-A01B-B6C897E38420}")
  • Get({Guid}) : Returns a single record by GUID PK. If the class doesn't use GUID PK's, null is returned.
  • Get(DataObject condition) : Returns multiple objects based on the query object's populated values.
  • Get(List<DataObject> conditions) : Returns multiple objects based on multiple conditions. Multiple conditions with the same types are treated as OR conditions. Conditions of different types are treated as AND conditions.
  • Get(condition(s), Boolean fuzzy, String order, Int32 limit, T start)
    • fuzzy: Whether LIKE is used instead of = when searching
    • order: An order-by string to insert in the order by X clause
    • limit: The maximum number of rows to return
    • start: A record indicating which record to start returning after. It should matche the return type and have the order (or default order) field populated. Very useful for building efficient result-paging.

In all cases, when a given DataObject condition matches the return type, the populated values are applied directly as conditions of the return values. If a condition is of a different type, the QueryBuilder attempts to find the relationship path between the object and the return type, and the conditions are applied to the related object.


This method is added as an instance method. It checks for the status of the object's PK to determine whether to perform a SQL UPDATE or INSERT. For integer PK's, it assumes an auto-incremented PK and let's the database select the value. For GUID PK's, it generates its own. In either case, successful Save()'s ensure the PK field on the object is populated after the data work is done. It returns true for a successful save.

For example:

var line = new LineItem() {
  OrderId = new Guid("{622E2962-2E91-4105-A01B-B6C897E38420}")
line.LineItemId; // is now populated

Last edited Aug 15, 2014 at 4:06 PM by svidgen, version 2