2013-05-19 7 views
1

하자 내가하여 Northwind 데이터베이스를 사용하여 엔티티 customer을 말한다. 내가 partial class customer에서 함수 GetCustomerByID을 만든 경우는 LINQ에 엔티티에 기능을 추가

. 제가 partial class dx_northwindDataContext 아래의 함수를 생성하는 경우 등

Dim q = From t in db.Customers where t.GetCustomerByID(my_parameter) Select T 

으로 I는 Linq 쿼리를 사용하여이 기능을 실행할 수있다. 내 데이터베이스에 대한 데이터 액세스 레이어를 생성하고 있기 때문에

Dim result = db.GetCustomerByID(my_parameter) 

하고 db 변수에 내 모든 개체에 내 모든 기능을 노출하지 않는 : 나는 사용하여이 기능을 실행할 수 있습니다. 내 기능을 호출하는 방법을 찾고있었습니다.

Dim result = db.Customers.GetCustomerByID(my_parameter) 

멀리 있습니까?

답변

2

예, 같은 db.Customers에 대한 an extension을 만들 수 있습니다

Imports System.Runtime.CompilerServices 

    Module IQueryableExtensions 

     <Extension()> 
     Public Function GetCustomerByID(ByVal source As IQueryable(Of Customer), ByVal id As Int32) As IQueryable(Of Customer) 
      return source.Where(Function(f)f.Id == id) 
     End Sub 

    End Module 
+0

가 마법처럼 작동합니다 ... 감사합니다. –