Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to VB. I am trying to reduce the coding needed for datacontext statements in LINQ. I need to use a large number of these statements which are all the same except for the table that is accessed. The statement I am using is as follows:

Public Shared Function GetEmployeeTable() As _
System.Data.Linq.Table(Of Employee)

Dim dc As New NorthwindDataClassesDataContext()
Return dc.GetTable(Of Employee)()

End Function

I would like to use this statement over and over by using a variable instead of hard coding the table name. All the LINQ examples I have seen hard code the table name (and use a separate datacontext function for each table). I have tried using variables in every way that I can think of.

Is there a way to include variables in these statements so that I can call the same function to access different tables? If so, can you give me an example

Thanks for your help.

Larry Toone
Posted

1 solution

larrytoone wrote:
System.Data.Linq.Table(Of Employee)


Changing this bit would mean using Generics, I would expect.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900