Extend method on QueryContent

Coordinator
Dec 17, 2009 at 3:51 AM
Edited Dec 17, 2009 at 3:54 AM

henq asked for a Page function on QueryContent to replace PageSize like:

 

Page(int curpage,int pagesize)

 

I don't agree with this idea, but I decided to allow people to do it outside.

After change set 62339, you can define the function in your own assembly like:

 

public static class MyExtends
{
    public static IList Page<T>(this IRangeable<T> w, long pageIndex, int pageSize)  where T : class, IDbObject
    {
        var mw = (QueryContent<T>) w;
        var ps = new PagedSelector<T>(mw.m_where, mw.m_order, pageSize, mw.m_entry);
        return ps.GetCurrentPage(pageIndex);
    }
}

 

And it will allow page function like:

 

var list = DbEntry.From<User>().Where(Condition.Empty).OrderBy("Id").Page(10, 20);

 

 

Dec 17, 2009 at 4:44 AM

Thanks!

Now,I THINK YOU ARE RIGHT!

Haven't find ps.GetCurrentPage.

Sorry!

I was blundering.

 

Dec 17, 2009 at 4:58 AM
1:oracle上的空值问题,确实如你所说。看来,我只能把这个字段设置成可空了。
2:分页的方法,你是对的,我前边用分页的时候是在pagecollection上找返回某一页的数据,没看到pageselector上的GetCurrentPage(pageIndex);返回某页的数据。
抱歉,我只看了官方的文档,没仔细看每个类上的方法。太浮躁了。
还有一个疑惑,allownull是不是弃用了?我在属性上边加了allownull,报错,如果是可空的直接用nullable类型就可以了?
Coordinator
Dec 17, 2009 at 5:03 AM

AllowNull 只用于非 ValueType,如果是ValueType,使用可空类型已经明确说明用户想用可为null的值,所以不需要定义AllowNull,所以我决定,不允许在ValueType上定义AllowNull属性。

 

Dec 17, 2009 at 1:36 PM

就是string 才用AllowNull

int就是int?

DateTime就是 DateTime?

long?