-
Notifications
You must be signed in to change notification settings - Fork 22
Projections in Chain
If you just want a subset of the columns returned by a table or view, the easiest way to create a projection is to use the ToObject<T>
or ToCollection<T>
materializer. This will generate a SELECT statement that only contains columns on the table/view that match the properties on the object.
You can also request just a single column using the ToXxxList materializers (where Xxx is the type: string, int, etc.).
When returning the results of an Insert, Update, or Upsert operation, the default behavior is to return nothing or the primary key. If you use the ToObject<T>
or ToCollection<T>
materializer, it will perform use the same logic for generating an OUTPUT clause.
Chain isn't designed to be a fully functional SQL generator. Most of the time it is expected that any non-trivial projection will be expressed in terms of a view or stored procedure. While this can be more work than a full ORM, it does allow you to take advantage of database-specific functionality that EF doesn't offer such as windowing functions.