entity-framework-core

Case insensitive name of tables and properties in Entity Framework 7

喜欢而已 提交于 2019-12-09 13:09:17
问题 I use Entity Framework 7 with Npgsql adapter. Sql generated by EF seems like SELECT "r"."Id", "r"."Name" FROM "public"."Role" AS "r" and it doesn't work in Postgres, because case-sensitive policy. To make it work i need to write create table script CREATE TABLE "Role" ( "Id" int, "Name" varchar(200) ); But it's ugly. Is there the way to make EF generate scripts without quotes or with lowercase naming style? 回答1: There's a very good reason Npgsql generates quotes everywhere - so you definitely

EF 7 Migration to Existing Database

旧街凉风 提交于 2019-12-09 12:22:55
问题 I am working on a web project using ASP.Net 5 and EF7. I have imported all the tables from existing database onto my models in my project. However, I am having problems in regards with migrations. I have created the initial migration, made some changes on particular entity, create another migration following the changes I have made and now want to apply the changes on the database. After running this command below: dnx ef database update [Migration] the dnx is trying to apply the 'initial'

Entity Framework Core: Is it safe to delete Migration.Designer.cs if we will never Revert a migration?

此生再无相见时 提交于 2019-12-09 11:05:44
问题 We have a database schema with ~200 tables. Model snapshot (Migration.Designer.cs) which is created for each migration is ~20K lines. So, having quite a number of migrations really slows down our build on CI (with ~30 migrations building a solution takes 6 minutes with migrations or 4 minutes without them). So, to the question: is it safe to delete model snapshots for old migrations (that we know we will never Revert)? Are model snapshots used for anything else except Revert-Migration? 回答1:

Mocking Entity Framework Core context

有些话、适合烂在心里 提交于 2019-12-09 10:45:25
问题 I try to test my app so I need to mock my EF context. My code seems to be ok, but I have following exception: "System.ArgumentNullException : Value cannot be null. Parameter name: source" Here is my test method: var options = new DbContextOptionsBuilder<ProductContext>().Options; var settings = new SqlSettings { InMemory = true }; var context = new Mock<ProductContext>(options, settings); var mockTreeService = new TreeService(context.Object); await mockTreeService.CreateTreeAsync("Testing

Entity Framework Core 1.0 DbContext not scoped to http request

我只是一个虾纸丫 提交于 2019-12-09 06:44:35
问题 I understood by watching this video with Rowan Miller https://channel9.msdn.com/Series/Whats-New-with-ASPNET-5/06 (at minute 22) that the way of configuring Entity Framework Core (previously known as EF7) into an ASP.NET Core 1.0 app (previously known as ASP.NET 5) in Startup.cs is as follows: public void ConfigureServices(IServiceCollection services) { //Entity Framework 7 scoped per request?? services.AddEntityFramework() .AddSqlServer() .AddDbContext<MyDbContext>(options => { options

Create Tables on runtime in EF Core

ⅰ亾dé卋堺 提交于 2019-12-09 05:54:44
问题 I know I can use the following command to add a new migration and create the database : dotnet ef migrations add MigrationName -c DbContextName dotnet ef database update -c DbContextName but I need to create my database/tables on runtime. First I tried to do that by overriding OnModelCreating but I failed. It returned me an error pointing out that the tables have not been created Here is my dbcontext class public class AimeLoggerContext : DbContext { public AimeLoggerContext(DbContextOptions

How to Add an implementation of 'IDesignTimeDbContextFactory<DataContext>' to the project in asp.net-core-2.0

让人想犯罪 __ 提交于 2019-12-09 05:14:09
问题 Here are the list of packages which I have installed : Installed Packages I am using Entityframework core 2.0. First time I have successfully created database using entity framework code first migration(add-migration and update-database command). Now when I update my entities and try to run migration it's giving me following error. Unable to create an object of type 'DataContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/

Reconfigure dependencies when Integration testing ASP.NET Core Web API and EF Core

穿精又带淫゛_ 提交于 2019-12-09 02:18:31
问题 I'm following this tutorial Integration Testing with Entity Framework Core and SQL Server My code looks like this Integration Test Class public class ControllerRequestsShould : IDisposable { private readonly TestServer _server; private readonly HttpClient _client; private readonly YourContext _context; public ControllerRequestsShould() { // Arrange var serviceProvider = new ServiceCollection() .AddEntityFrameworkSqlServer() .BuildServiceProvider(); var builder = new DbContextOptionsBuilder

Composite Key EF Core getting error when using Fluent Api

不羁的心 提交于 2019-12-08 21:53:25
问题 So I have the following class in Entity Framework Core. I am trying to do a code first migration and can't for the life of me figure out how to make the fluent API for this work. public class Participants { public Activity Activity { get; set; } //Class with Id and Name of Activity public ApplicationUser Participant { get; set; } [Key] [Column(Order = 1)] public int ActivityId { get; set; } [Key] [Column(Order = 2)] public string ParticipantId { get; set; } } In EF6 I was able to do this in

Entity framework core, code first migration with data migration

允我心安 提交于 2019-12-08 20:38:22
问题 I am trying to use EF Core code first migrations to de-normalise an existing table. I have en existing table LoginEvent which data looks like this: ╔═════════════════════════════════════════════════╗ ║ LoginEvent ║ ╠════╦══════════╦═══════════╦════════════╦════════╣ ║ Id ║ VenueRef ║ VenueName ║ OccurredAt ║ UserId ║ ╠════╬══════════╬═══════════╬════════════╬════════╣ ║ 1 ║ ven01 ║ Venue 1 ║ 2018-01-29 ║ 5 ║ ╠════╬══════════╬═══════════╬════════════╬════════╣ ║ 2 ║ ven02 ║ Venue 2 ║ 2018-01