vb.net - LINQ-to-SQL Generic GetByIDs method -
i'm using object it's primary key value.
i'm trying find way create similar method getbyids can pass ienumerable(of object) , ids.contains(pk), there's no contains expression.
anyone know how this?
public function getbyid(of t class)(byval pk object) t dim itemparam = expression.parameter(gettype(t), "item") return gettable(of t).single( expression.lambda(of func(of t, boolean))( expression.equal( expression.property(itemparam, getprimarykeyname(of t)), expression.constant(pk) ), new parameterexpression() {itemparam} ) ) end function public function getprimarykeyname(of t)() string return mapping.gettable(gettype(t)).rowtype.identitymembers(0).name end function
you need use expression.call
update - different overload
expression.call(typeof(enumerable), "contains", new type[] { expression.constant(...).type } expression.property(...), expression.constant(...));
Comments
Post a Comment