能够重用对数据上下文的函数调用 [英] Ability to reuse function calls to datacontext

查看:78
本文介绍了能够重用对数据上下文的函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VB的新手.我正在尝试减少LINQ中datacontext语句所需的编码.我需要使用大量的这些语句,除了被访问的表之外,其他所有语句都是相同的.我正在使用的语句如下:

_
的公共共享函数GetEmployeeTable() System.Data.Linq.Table(员工)

昏暗的dc作为新的NorthwindDataClassesDataContext()
返回dc.GetTable(Employee)()

最终功能

我想通过使用变量而不是对表名进行硬编码来一遍又一遍地使用此语句.我看到的所有LINQ示例都对表名进行了硬编码(并对每个表使用单独的datacontext函数).我尝试过以我能想到的所有方式使用变量.

有没有办法在这些语句中包括变量,以便我可以调用相同的函数来访问不同的表?如果可以,请给我一个例子

感谢您的帮助.

Larry Toone

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

推荐答案

larrytoone写道:
larrytoone wrote:

System.Data.Linq.Table(员工)

System.Data.Linq.Table(Of Employee)



我希望更改此位将意味着使用泛型.



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


这篇关于能够重用对数据上下文的函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆