[英]Check if column exists in linq
I have database of external program that I want to connect and operate on through LINQ to SQL. 我有要连接的外部程序数据库,并希望通过LINQ to SQL进行操作。 My problem is , I want to support wider range of versions of database, so I have to check for columns if they exists. 我的问题是,我想支持更大范围的数据库版本,因此我必须检查列是否存在。
I tried something like that: 我尝试过这样的事情:
IEnumerable<string> k = db.ExecuteQuery<string>("select column_name from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME='{0}' and TABLE_NAME='POSIEDZENIA'", column);
And it gives me nothing. 它什么也没有给我。 k.Count() gives error: k.Count()给出错误:
The result of a query cannot be enumerated more than once 查询结果不能被多次枚举
When I cast it to List by ToList() it gives 0 count. 当我通过ToList()将其转换为List时,它的计数为0。
I'm sure that this column exists in database that datacontext is connected to. 我确定该列存在于datacontext连接到的数据库中。
Have you any suggestions? 有什么建议吗?
Just remove quotation around parameter ( {0}
). 只需删除参数( {0}
)周围的引号即可。
IEnumerable<string> k = db.ExecuteQuery<string>("select column_name from
INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME={0} and TABLE_NAME='POSIEDZENIA'", column);
for more information visit this msdn article . 有关更多信息,请访问此msdn文章 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.