Pineapple.Data for SQL Server
dotnet add package Pineapple.Data
Pineapple.Data adds SQL Server helpers on top of Pineapple. It targets .NET 8 (EF Core 8) and .NET 10 (EF Core 10) and uses Microsoft.Data.SqlClient 7.
InformationSchemaContext
An EF Core DbContext mapped to SQL Server’s INFORMATION_SCHEMA views, so you can explore a database’s schema with LINQ. All queries are no-tracking.
using Pineapple.Data.InformationSchema;
await using var schema = new InformationSchemaContext(connectionString);
var primaryKeys =
from c in schema.TableConstraints
where c.ConstraintType == "PRIMARY KEY"
join k in schema.KeyColumns on c.ConstraintName equals k.ConstraintName
orderby k.TableSchema, k.TableName, k.Position
select new { k.TableSchema, k.TableName, k.ColumnName };
foreach (var pk in await primaryKeys.ToListAsync())
Console.WriteLine($"{pk.TableSchema}.{pk.TableName}.{pk.ColumnName}");
| Set | View | Columns |
|---|---|---|
Tables |
INFORMATION_SCHEMA.TABLES |
TableCatalog, TableSchema, TableName |
Columns |
INFORMATION_SCHEMA.COLUMNS |
… ColumnName, DataType |
KeyColumns |
INFORMATION_SCHEMA.KEY_COLUMN_USAGE |
… ColumnName, Position, ConstraintName |
TableConstraints |
INFORMATION_SCHEMA.TABLE_CONSTRAINTS |
… ConstraintType, ConstraintName |
SqlClient.Check.IsSqlServerAvailable
Parses the server and port (default 1433) from a connection string and probes the TCP endpoint up to three times — handy for waking a paused Azure SQL serverless database before the first query.
using Pineapple.Data.SqlClient;
Check.IsSqlServerAvailable(connectionString);
In 2.0.0 this method returns
trueafter probing even if every attempt fails, so treat it as a wake-up call rather than a reliable check. UsePineapple.Health.Check.IsAlive(server, port)when you need the result.
Questions about Pineapple.Data
How do I list all tables and columns in SQL Server with Entity Framework Core?
Install Pineapple.Data and query new InformationSchemaContext(connectionString).Columns, which maps INFORMATION_SCHEMA.COLUMNS to a LINQ-queryable, no-tracking EF Core set.