c# - How i can add Couchbase Documents in a list? -
i'm experimenting couchbase + xamarin.forms trying simple search, showing results in listview i've stuck. :( know how add rows/documents of query in list?
public list<visitor> searchrecord (string word) { var viewbyname = db.getview ("byname"); viewbyname.setmap((doc, emit) => { emit (new object[] {doc["first_name"], doc["last_name"]}, doc); }, "2"); var visitorquery = viewbyname.createquery(); visitorquery.startkey = new list<object> {word}; // visitorquery.endkey = new list<object> {word, new dictionary<string, object>()}; visitorquery.limit = 100; var visitors = visitorquery.run(); var visitorlist = new list<visitor> (); foreach (var visitor in visitors) { // visitorlist.add(visitor.document); <-- error. system.console.writeline(visitor.key); } return visitorlist; }
i error messages:
error cs1501: no overload method
add' takes
2' arguments (cs1501) (demo_couchbase.droid) error cs1502: best overloaded method matchsystem.collections.generic.list<demo_couchbase.visitor>.add(demo_couchbase.visitor)' has invalid arguments (cs1502) (registroagil_couchbase.droid) error cs1503: argument
#1' cannot convertcouchbase.lite.document' expression type
demo_couchbase.visitor' (cs1503) (demo_couchbase.droid)
thank in advance can provide.
there problem in mapping part. can directly cast documents on getview. can try bellow code.
public list<visitor> searchrecord (string word) { var viewbyname = db.getview<visitor>("byname","byname"); var visitorquery = viewbyname.createquery(); visitorquery.startkey = new list<object> {word}; visitorquery.limit = 100; var visitors = visitorquery.run(); var visitorlist = new list<visitor> (); foreach (var visitor in visitors) { visitorlist.add(visitor.document); system.console.writeline(visitor.key); } return visitorlist; }