【发布时间】:2018-02-13 15:28:47
【问题描述】:
我正在寻找一种方法来创建通用函数/属性以从我的数据上下文中获取表。 现在我有几个属性,每个属性都调用 GetTable 函数,但我想将它们加入一个通用函数中。
Partial Public Class SAdminDataContext
Inherits DataContext
Public ReadOnly Property GetCustomer() As Table(Of Customer)
Get
Try
Return GetTable(Of Customer)()
Catch ex As Exception
Return Nothing
End Try
End Get
End Property
'...
Public ReadOnly Property GetCustomerPerson() As Table(Of CustomerPerson)
Get
Try
Return GetTable(Of CustomerPerson)()
Catch ex As Exception
Return Nothing
End Try
End Get
End Property End Class
然后我得到这样的数据:
dim datasource = dataContext.GetCustomer
【问题讨论】:
-
GetTable(Of T) 方法呢?