In MicroLite 2.0, we introduced the Dynamic Projections feature and although useful, it did suffer from a couple of small limitations.
- Firstly, it wasn’t compatible with the Include API so you had to perform 2 separate queries if you wanted to query a mapped class and also display a projection.
- Secondly, you had to manually implement paging as projection had no paging capability.
- Thirdly, it always retuned a collection so it was more effort to return a single record.
In order to address these limitations, the
.Projection() method has been obsoleted and instead the
dynamic keyword can be used the following methods:
ISession.Include.Many<dynamic>(); ISession.Include.Single<dynamic>(SqlQuery); ISession.Fetch<dynamic>(); // This is the direct replacement for ISession.Projection() ISession.Paged<dynamic>(); ISession.Single<dynamic>(SqlQuery);
In addition to the change to dynamic support, the methods listed above can also be supplied with primitive types and a query which is restricted to a single column:
var dates = session.Fetch<DateTime>(new SqlQuery("SELECT Date FROM Table"));
This makes it much easier to use dynamic projections in your application.