经过周末的通宵,发布了组件1.0版本

对组件进行了扩展,最大的修改就是增加缓存查询,以获得更好的性能。

 

本节先讲一些小的扩展修改。

 

之前版本ToScalar()只是返回object。

现在增加了ToScalar<TResult>()方法,组件自动转换类型。

例如:

DbSession.Default.From<Products>().Select(Products._.ProductID).Top(1).ToScalar<int>();

这样就返回类型为int类型,免去转换的代码。

当查询出来的值为null 或者DbNull ,该转换则返回default(TResult) 。

 

随之扩展了DbSession的方法:

Sum<TEntity, TResult>(Field field, WhereClip where)

Max<TEntity, TResult>(Field field, WhereClip where)

Min<TEntity, TResult>(Field field, WhereClip where)

Avg<TEntity, TResult>(Field field, WhereClip where)

返回需要的类型。

例如:

DbSession.Default.Avg<Products,decimal>(Products._.UnitPrice, WhereClip.All);

这样返回回来的就是decimal 类型的数据。

 

DbSession还增加了Exists<TEntity>(WhereClip where)

判断是否存在记录,返回bool。

 

下一节将讲述缓存查询。

posted on 2010-02-07 21:01  steven hu  阅读(3109)  评论(5编辑  收藏  举报