views:

103

answers:

4

What is a Projection, in terms of database theory and NHibernate when using SetProjection()?

+7  A: 

Very simply, it's a function which takes an input (e.g. a database row) and produces an output (e.g. one of the columns from the row, or perhaps some calculation based on multiple columns).

Jon Skeet
+1  A: 

Think of it like functions on a piece of a db. I found this article very helpful.

Shane Reustle
A: 

Projection is one of the basic operations of Relational Algebra. It takes a relation and a (possibly empty) list of attributes of that relation as input. It outputs a relation containing only the specified list of attributes with duplicate tuples removed. In other words the output must also be a relation.

Example, if the relation R{A,B}, contains three tuples {1,10},{2,10},{3,20} then the projection of R over the attribute list {B} would contain 2 tuples: {10},{20}.

In short, projection is more or less equivalent to SELECT DISTINCT in SQL (excluding cases with nulls and duplicate columns).

dportas
+1  A: 

In terms of hibernate, it's like specifying what columns to select. As opposed to letting the mappings determine what columns are fetched. This means you can specify sql functions, subqueries, a single column, or maybe all of the above via a ProjectionList. For example, if you wanted to count the rows in a table SetProjection(Projections.RowCount()).

dotjoe