i using visual studio, c# , sqlite xamarin application , working well. using generic repository extend able add add check against 2 properties if generic of specific type.
here generic respository pattern following
my sets right looks this:
public list<t> get<tvalue>(expression<func<t, bool>> predicate = null, expression<func<t, tvalue>> orderby = null) { var query = db.table<t>(); if (predicate != null) query = query.where(predicate); if (orderby != null) query = query.orderby<tvalue>(orderby); return new list<t>(query); }
however add (pseudo code):
where recordowner type , recordownercompanyid , recordowneruserid properties add predicate/where clause. keep in mind hte lambda not work , sqlite(query of type tablequery<t>
)
public list<t> get<tvalue>(expression<func<t, bool>> predicate = null, expression<func<t, tvalue>> orderby = null) { var query = db.table<t>(); if (predicate != null) query = query.where(predicate); if (orderby != null) query = query.orderby<tvalue>(orderby); // perform record owner checks if (typeof(recordowner).isassignablefrom(typeof(t))) { query = query.where(x => recordownercompanyid == 1234 && x.recordowneruserid == 1234); } return new list<t>(query); }
any appreciated.
update:
i have working solution want prefer solve problem predicate , way shown below using more memory 2 lists. has not been negative impact on performance not ideal solution looking for. if knows how can predicate great.
new working example (not using predicate):
public list<t> get<tvalue>(expression<func<t, bool>> predicate = null, expression<func<t, tvalue>> orderby = null) { var query = db.table<t>(); if (predicate != null) query = query.where(predicate); if (orderby != null) query = query.orderby<tvalue>(orderby); var memuser = jstmem.default.user; // perform record owner checks if (typeof(recordowner).isassignablefrom(typeof(t))) { return new list<t>(query).where(x => (x recordowner).recordownercompanyid == memuser.selectedcompanyid && (x recordowner).recordowneruserid == memuser.userid).tolist(); } return new list<t>(query); }
Comments
Post a Comment