entity framework core 2 doesn't see sqlite extensions

.net-core-2.0 entity-framework-core

Question

So with entity framework 1.1 I had entities like this

 modelBuilder.Entity<Resolution>()
      .Property(r => r.Created)
      .ValueGeneratedOnAddOrUpdate()
      .ForSqliteHasColumnType("Timestamp")            
      .ForSqliteHasDefaultValueSql("CURRENT_TIMESTAMP");

 modelBuilder.Entity<Resolution>()
      .Property(r => r.Updated)
      .ForSqliteHasColumnType("Timestamp")
      .IsRequired();

which worked fine. After upgrading to .net core 2.0 and entity framework 2.0 the

 .ForSqliteHasColumnType("Timestamp")

doesn't seem to be available anymore. In fact all "ForSqlite*" functions aren't there.

I upgraded the "Microsoft.EntityFrameworkCore.Sqlite" to 2.0. I have

using Microsoft.EntityFrameworkCore;

Did they change something? I can't seem to find anything in the docs other then the sql providers are not backwards compatible to .NET Core 1.1.

Thanks

1
2
8/15/2017 3:47:32 AM

Accepted Answer

I didn't find anywhere said about the changes. But you can use below code instead in EF Core 2.0.

.HasDefaultValueSql("CURRENT_TIMESTAMP");
2
8/15/2017 1:10:23 PM

Popular Answer

I had a similar problem after upgrading a testproject to EF Core 2.0 yesterday, in my case the database was not SQLite, but MS SQL Server.

I had to replace

 b.Property(e => e.StartDate).IsRequired().ForSqlServerHasColumnType("Date"); 
 b.Property(e => e.LastModified).IsRequired().ForSqlServerHasColumnType("SmallDateTime");

with:

 b.Property(e => e.StartDate).IsRequired().HasColumnType("Date"); 
 b.Property(e => e.LastModified).IsRequired().HasColumnType("SmallDateTime");

But after that it was working again. I tested it by recreating the database and visually checking the newly created column definitions in MS SQL Server Management Studio.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow