vb.net 2010 - Add Function to entity in LINQ -


let have entity customer using northwind database.

if created function getcustomerbyid under partial class customer. can execute function using linq query such as

dim q = t in db.customers t.getcustomerbyid(my_parameter) select t 

if created function under partial class dx_northwinddatacontext. can execute function using :

dim result = db.getcustomerbyid(my_parameter) 

since creating data access layer database, , not exposing function entity db variable. looking way of calling functions :

dim result = db.customers.getcustomerbyid(my_parameter) 

is there away that?

yes, can create an extension db.customers like:

imports system.runtime.compilerservices      module iqueryableextensions          <extension()>          public function getcustomerbyid(byval source iqueryable(of customer), byval id int32) iqueryable(of customer)             return source.where(function(f)f.id == id)         end sub      end module 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -