asp.net - Load object from RavenDB -
i'm trying refactoring on project. want replace code between lines , 2 commented lines above can use on page need quote object
//quote.loadactive(); //quoteid = quote.id; //-------------------------------------------------------- list<quote> dbquotes = session.query<quote>() .customize(x => x.waitfornonstaleresultsasoflastwrite()) .tolist(); foreach (quote q in dbquotes) { if (q.isactive) { quoteid = q.id; quote = session.load<quote>(q.id); } } //--------------------------------------------------------
here's loadactive() function inside quote class
public quote loadactive() { list<quote> dbquotes = session.query<quote>() .customize(x => x.waitfornonstaleresultsasoflastwrite()) .tolist(); foreach (quote q in dbquotes) if (q.isactive) return session.load<quote>(q.id); return new quote(); }
but don't know how update quote object. can't update inside function without doing element element , that's tedious. if try , quote = quote.loadactive() complains quote hasn't been initialized. i'm sure there's way set i'm trying i'm blanking , can't think of keywords google question. couldn't come subject wording post!
edit: tl;dr need load active quote 'quote' object used page. what's in between lines works, want replace commented lines above (or similar).
you're quote object should not responsible accessing database. should using data access class or better yet, query handler access db.
i think might little confused code doing. let me try explain.
public quote loadactive() { //this call returns every quote document in db //ravendb default return max of 128 w/out doing paging list<quote> dbquotes = session.query<quote>() .customize(x => x.waitfornonstaleresultsasoflastwrite()) .tolist(); //this doesn't make sense. you're saying first quote active, //make expensive db call , return same object. //i still don't know want do, have quote object //why go db , have? foreach (quote q in dbquotes) if (q.isactive) return session.load<quote>(q.id);//unnecessary, have quote //return q; return new quote(); //if there's no active quotes return empty quote object }
are trying return active quotes db? can this
var activequotes = session.query<quote>() .where(x => x.isactive == true) .tolist();//remember, ravendb's safe default feature //will return 128 records, have //implement paging
Comments
Post a Comment