SQLCommandType.视图-为什么MS不提供这个?
本文关键字:视图 为什么 MS SQLCommandType | 更新日期: 2023-09-27 18:02:13
我们看到System.Data.CommandType只有3个枚举:"StoredProcedure", "TableDirect"answers"Text"。为什么我们不把"查看"作为一个选项呢?微软不提供这个选项的具体原因是什么?
我在这里特别讨论的是SQL Server视图。
因为View
可以通过TableDirect
或Text
访问。最常见的访问是Text
,因为您通常会这样做:
DataTable dt = new DataTable();
using (SqlConnection c = new SqlConnection(cString))
{
using (SqlDataAdapter sda = new SqlDataAdapter(sql, c))
{
sda.SelectCommand.Parameters.Add("parm1", value1);
c.Open();
sda.Fill(dt);
}
}
最后,视图实际上在SQL Server中表示为一个表。它有一个真正的表定义,它恰好是用一个查询构建的。
大多数时候视图本身不使用,而是作为查询或SP的一部分。因此没有必要提供专用的CommandType。函数也是一样——没有CommandType.Function.