ASP.NET Core 1 RC2 - database schema

user2818430

Can somebody advise how to get the schema in ASP.NET Core 1 RC2?

using (SqlConnection connection = new SqlConnection("Server=.;Database=Mydb;Trusted_Connection=True;MultipleActiveResultSets=true"))
        {
            connection.Open();
            connection.GetSchema("Tables"); // doesn't work

        }
Gary Holland

The connection.GetSchema has been depreciated in Asp.Net Core due as it returns the DataTable which has also been depreciated. The way to do this now is is to open run the ExecuteReader() function, and then use the GetSchemaColumn() function from the resulting reader object.

Here is a sample:

    public static void Main(string[] args)
    {
            using (SqlConnection connection = new SqlConnection("Server=(localdb)\\v11.0;Database=MyAdventureWorks;Trusted_Connection=True"))
            {

                connection.Open();

                SqlCommand cmd = new SqlCommand("select * from [Person].[Person]", connection);
                DbDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.SchemaOnly);

                if (reader.CanGetColumnSchema())
                {
                    var columns = reader.GetColumnSchema();
                    foreach (var column in columns)
                    {
                        Console.Write("ColumName: " + column.ColumnName);
                        Console.Write(", DataTypeName: " + column.DataTypeName);
                        Console.Write(", ColumnSize: " + column.ColumnSize);
                        Console.WriteLine(", IsUnique: " + column.IsUnique);
                    }
                }
                else
                    throw new Exception("Connection does not support GetColumnSchema.");
            }

            Console.ReadLine();
    }

Note: I think this is still be stabalized in Rc2. For example the column.IsKey function always returning null.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ASP.NET Core 1 RC2 - database schema

From Dev

ASP.NET Core RC2 Identity Database Schema Migrations

From Dev

ASP.NET Core RC2 Seed Database

From Dev

asp net core 1 RC2 AccountController injection

From Dev

asp.net core 1.0 mvc RC2 tagBuilder method with HtmlEncoder() worked in RC1 not working RC2

From Dev

Issues after migration of Asp.Net Core RC1 to RC2

From Dev

Asp.net core RC1 to RC2 integration testing: where did UseServices go?

From Dev

Entity framework Core with Identity and ASP.NET Core RC2 not creating user in database

From Dev

Entity framework Core with Identity and ASP.NET Core RC2 not creating user in database

From Dev

ASP.NET Core 1 RC2 web application entry point

From Dev

asp.net core 1 rc2: Creating a view component

From Dev

EntityFramework Core database scaffolding (.NET Core RC2)

From Dev

xunit does not compile with ASP.NET Core RC2

From Dev

ASP.NET Core RC2 Area not published

From Dev

Using swagger in asp.net core RC2

From Dev

Cookies in ASP.NET Core rc2

From Dev

Publish rc2 asp.net core application to Azure

From Dev

Url rewriting in ASP.NET Core RC2

From Dev

ASP.NET Core RC2 Configure Custom AppSettings

From Dev

ASP.NET Core RC2 as linux deamon

From Dev

Url rewriting in ASP.NET Core RC2

From Dev

Is ASP.NET Core RC2 Released?

From Dev

cannot add reference to .net core Class library asp.net core rc2

From Dev

.NET Core RC2 applicationhost.config incompatible with ASP.NET .NET 4.6?

From Dev

Why I'm getting this incompatibilities issues migrating from .net core rc1 to rc2

From Dev

Whats the differences between .net Core Installer (RC2) and .Net Core SDK Installer (Preview 1)?

From Dev

Shared cookie authentication between ASP.NET Core RC2 and .NET 4.5.1 apps

From Dev

Using net451 libraries in an ASP.NET Core application (RC2)

From Dev

Shared cookie authentication between ASP.NET Core RC2 and .NET 4.5.1 apps

Related Related

  1. 1

    ASP.NET Core 1 RC2 - database schema

  2. 2

    ASP.NET Core RC2 Identity Database Schema Migrations

  3. 3

    ASP.NET Core RC2 Seed Database

  4. 4

    asp net core 1 RC2 AccountController injection

  5. 5

    asp.net core 1.0 mvc RC2 tagBuilder method with HtmlEncoder() worked in RC1 not working RC2

  6. 6

    Issues after migration of Asp.Net Core RC1 to RC2

  7. 7

    Asp.net core RC1 to RC2 integration testing: where did UseServices go?

  8. 8

    Entity framework Core with Identity and ASP.NET Core RC2 not creating user in database

  9. 9

    Entity framework Core with Identity and ASP.NET Core RC2 not creating user in database

  10. 10

    ASP.NET Core 1 RC2 web application entry point

  11. 11

    asp.net core 1 rc2: Creating a view component

  12. 12

    EntityFramework Core database scaffolding (.NET Core RC2)

  13. 13

    xunit does not compile with ASP.NET Core RC2

  14. 14

    ASP.NET Core RC2 Area not published

  15. 15

    Using swagger in asp.net core RC2

  16. 16

    Cookies in ASP.NET Core rc2

  17. 17

    Publish rc2 asp.net core application to Azure

  18. 18

    Url rewriting in ASP.NET Core RC2

  19. 19

    ASP.NET Core RC2 Configure Custom AppSettings

  20. 20

    ASP.NET Core RC2 as linux deamon

  21. 21

    Url rewriting in ASP.NET Core RC2

  22. 22

    Is ASP.NET Core RC2 Released?

  23. 23

    cannot add reference to .net core Class library asp.net core rc2

  24. 24

    .NET Core RC2 applicationhost.config incompatible with ASP.NET .NET 4.6?

  25. 25

    Why I'm getting this incompatibilities issues migrating from .net core rc1 to rc2

  26. 26

    Whats the differences between .net Core Installer (RC2) and .Net Core SDK Installer (Preview 1)?

  27. 27

    Shared cookie authentication between ASP.NET Core RC2 and .NET 4.5.1 apps

  28. 28

    Using net451 libraries in an ASP.NET Core application (RC2)

  29. 29

    Shared cookie authentication between ASP.NET Core RC2 and .NET 4.5.1 apps

HotTag

Archive