-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
This is to unwrap the specific issue of resultset schemas from the many involved in #14302.
Back on May 5th @davkean noted:
We want GetSchemaTable in some form (we should get a separate bug filed on that, however, as you could imagine bringing that back with a different design that doesn't pull in DataSet/DataTable).
While it doesn't seem that anyone cares what method exists for of getting the schema of a resultset, we seem to agree on needing a method of doing it in .Net Core. For example, if a user runs a simple query such as:
SELECT 'bob' Name, 1 Id
Then there's no way to see what the types are. While getting the .Net type (via .GetFieldType()
, e.g. DateTime
) is possible and getting part the SQL type (via .GetDataTypeName()
, e.g. NVARCHAR
) is possible, other vital attributes of the schema shape currently aren't possible. For example there's no way to distinguish a varchar(20)
from a varchar(max)
. There's also no way to tell if the column was nullable. Previously, this functionality was provided by .GetSchemaTable()
which returned a DataTable
class.
Currently I have a very simple use case: query data here, create a table with that data elsewhere. The query can be something like: SELECT * FROM sys.database_files
. I point this out to illustrate that INFORMATION_SCHEMA
(as proposed by some in #14302 as an alternative) is not a viable option. The same issue presents on any stored procedure which can also return any result set shape depending on the code paths. We need a way to see the scheme of a result set, these database-query alternatives are both expensive and non-covering.
This is a hard blocker for projects of myself and others. I have uses in both one-off projects as well as Opserver (which monitors SQL) and Dapper.Net. I know from #14302 that I'm not alone on this block. The portability of .Net core is extremely appealing for certain projects, especially those where we need to monitor the innards of SQL without depending on a .Net install (many if not most existing SQL servers only have .Net 3.5). Unfortunately though, this one missing piece of the puzzle may prevent using it altogether, forcing full CLR installs.
While SqlClient specifically serves my blocking use case, it's important to point out as @FransBouma notes in the other issue: this needs to be in the base API, not specifically up in SqlClient. For example, I also need this for Dapper features and it works across many providers - it is not at all SQL Server specific.
So how about it, can we please get an API for result set schemas added back? I'm happy to contribute to designing and provide feedback on a new API here if that's the best route. I know many others are as well.