简体   繁体   中英

How to do pagination in couchdb using loveseat in c#

I need to do page load on scroll down in my application. I am using couchdb as my back end and I found a pagination option in couchdb which I think would satisfy my issue.

The thing is I can't find any working examples for pagination anywhere. I need someone's help in making my application work with this one.

Take a look at this for reference: https://github.com/soitgoes/LoveSeat/blob/master/LoveSeat/PagingHelper.cs

This is my code. I am getting an error in the options = model.GetOptions(); line, saying "object reference not set to an instance of an object".

public List<newVO> Getdocs(IPageableModel model)
    {
        List<newVO> resultList = new List<newVO>();
        var etag = "";
        ViewOptions options = new ViewOptions();
        options = model.GetOptions();
        options.StartKeyDocId = lastId;
        options.Limit = 13;
        options.Skip = 1;
        var result = oCouchDB.View<newVO>("GetAlldocs", options);
        //model.UpdatePaging(options, result);
        if (result.StatusCode == HttpStatusCode.NotModified)
        {
            response.StatusCode = "0";
            return null;
        }
        if (result != null)
        {
            foreach (newVO newvo in result.Items)
            {
                resultList.Add(newvo );
            }
        }

        return resultList;

    }

Thanks in advance. All ideas are welcome.


public List<newVO> Getdocs(IPageableModel model)
        {
            List<newVO> resultList = new List<newVO>();
            var etag = "";
            ViewOptions options = new ViewOptions();
            options = model.GetOptions();
            options.StartKeyDocId = lastId;
            options.Limit = 13;
            options.Skip = 1;
            var result = oCouchDB.View<newVO>("GetAlldocs", options);
            //model.UpdatePaging(options, result);
            if (result.StatusCode == HttpStatusCode.NotModified)
            {
                response.StatusCode = "0";
                return null;
            }
            if (result != null)
            {
                foreach (newVO newvo in result.Items)
                {
                    resultList.Add(newvo );
                }
            }

            return resultList;

        }

This is my code and i am getting error in "options = model.GetOptions();" line that object reference not set to an instance of an object...

I've not used the LoveSeat paging implementation, but you can use the Limit and Skip properties on the ViewOptions to achieve paging:

public static IEnumerable<T> GetPage(this ICouchDatabase couchDatabase,
    string viewName,
    string designDoc,
    int page,
    int pageSize)
{   
    return couchDatabase.View(viewName, new ViewOptions
    {
        Skip = page * pageSize,
        Limit = pageSize
    }, designDoc);
}

This simple extension method will get a page of data from a CouchDB view

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM