如何在linq中将表名动态传递给sql [英] How to pass table name dynamically in linq to sql
本文介绍了如何在linq中将表名动态传递给sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要您的帮助来解决此问题.
I need your help to resolve this issue.
如何在linq中动态将表名传递给C#.net中的sql?
How to pass table name dynamically in linq to sql in C#.net?
public IntPol(DataClasses1DataContext DC, decimal value,string tableName)
{
}
tableName
将动态更改.
推荐答案
如果我正确理解了这个问题,那么您可以做类似
If I understand the question correctly then you could do something like
public IntPol(DataClasses1DataContext DC, decimal value,string tableName)
{
DC = new DataClasses1DataContext("yourConnString");
var result = DC.Mapping.GetTables().SingleOrDefault(t => t.TableName.ToString() == tableName);
}
或者您也可以执行tableObject.GetType().Name
,但是如果类型是动态的,则可能必须单独发送Type tableType
.
Or you could also do tableObject.GetType().Name
but if type is dynamic might have to send Type tableType
separately.
这篇关于如何在linq中将表名动态传递给sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文