Drop table In the core of Entity Framework and UWP

I am learning Entity Framework with UWP. I tried to reset the table by deleting it from DbContext. When I run the code after the migration, I received an error message in which the primary key is not supported using UWP. This article https://docs.efproject.net/en/latest/providers/sqlite/limitations.html recommends using the sql (string) method. This article, https://msdn.microsoft.com/en-us/data/jj592907.aspx , has an example that I am trying to execute.

   using (var context = new BloggingContext())
        {
            var blogs = context.Blogs.SqlQuery("SELECT * FROM dbo.Blogs").ToList();
        }

I can not find the link. I like the idea of ​​using SQL statements. In another stackoverflow article, How to delete a table in Entity Framework Code First? , I don’t understand: "Write the DropTable operator in the Down method of [DateStamp] _InitialCreate.cs class and the table will be deleted." Isit is related to my problem. If so, how to implement it. Thanks.

0
source share
1 answer

I tried to delete the table by deleting it from the DbContext.

You can use db.Database.ExecuteSqlCommandto delete tables:

//you have to use this namespace
using Microsoft.EntityFrameworkCore;

using (var db = new BloggingContext())
{
     db.Database.ExecuteSqlCommand("DROP TABLE [Blogs]");
}

I don’t understand: "write a DropTable statement in the Down method of [DateStamp] _InitialCreate.cs class

<DateStamp>_<MigrationName>.cs (Add-MigrationMigrationName). Migrations. Down.

, db.Database.Migrate() ( App.xaml.cs). SQLite __EFMigrationsHistory, , <DateStamp>_<MigrationName>.cs. [Migration("<TimeStamp>_<MigrationName>")] , :

enter image description here

, , .

+1

All Articles