I'm working on a new application that's must show a table in a data grid. The columns for the data grid are retrieved by a SQL view that a colleague of mine wrote. However, the data returned looks like it repeats data, such as you get if the SQL query wasn't well formed. Here's code to define the SQL view:
Create view [Core].[vwDataDictionary] as
SELECT ROW_NUMBER() OVER(order by A.[TABLE_CATALOG]) AS [ID]
,A.[TABLE_CATALOG]
,A.[TABLE_SCHEMA]
,A.[TABLE_NAME]
,A.[COLUMN_NAME]
,[ORDINAL_POSITION]
,[COLUMN_DEFAULT]
,[IS_NULLABLE]
,[DATA_TYPE]
,[CHARACTER_MAXIMUM_LENGTH]
,[CHARACTER_OCTET_LENGTH]
,[NUMERIC_PRECISION]
,[NUMERIC_PRECISION_RADIX]
,[NUMERIC_SCALE]
,[DATETIME_PRECISION]
,[CHARACTER_SET_CATALOG]
,[CHARACTER_SET_SCHEMA]
,[CHARACTER_SET_NAME]
,[COLLATION_CATALOG]
,[COLLATION_SCHEMA]
,[COLLATION_NAME]
,[DOMAIN_CATALOG]
,[DOMAIN_SCHEMA]
,[DOMAIN_NAME]
,B.[CONSTRAINT_NAME]
,C.[CONSTRAINT_TYPE]
FROM [INFORMATION_SCHEMA].[COLUMNS] AS A
left join
[INFORMATION_SCHEMA].[CONSTRAINT_COLUMN_USAGE] AS B
on A.TABLE_NAME = B.TABLE_NAME and A.COLUMN_NAME = B.COLUMN_NAME
left join
[INFORMATION_SCHEMA].[TABLE_CONSTRAINTS] AS C
on B.CONSTRAINT_NAME = C.CONSTRAINT_NAME
where A.[TABLE_SCHEMA] = 'App'
However, the data grid show data like this:
So, I decided to simplify things by creating a console app to just pull the data from the view and iterate over what's returned. I used EF's code first with existing database. Here's the code for the console app:
class Program
{
static void Main(string[] args)
{
using (var ctx = new CodeModel())
{
var bozo = ctx.vwDataDictionaries.ToList();
int i = 0;
foreach (var item in bozo)
{
i++;
Console.WriteLine($"i: {i}, ID: {item.ID}, TABLE_NAME: {item.TABLE_NAME}, COLUMN_NAME: {item.COLUMN_NAME}");
}
}
Console.WriteLine("Finished");
}
}
But if I run that console app, I get values like this:
Running the query in the C# app returns 282 records. All have a column name of "ID". However, if I run the same query in Azure Data Studio, I get the following:
Of course, I know that I'm not sorting or filtering, but I still don't understand why the sample program is returning so many duplicates for COLUMN_NAME.
I'm working with VS 2019 version 16.8.2. .NET Framework 4.5.2 and EF 6.