entity-framework-core

Nuget error “Object reference not set to an instance of an object” while installing Entityframework 7 from Package Manager Console in VS2015

血红的双手。 提交于 2019-12-03 10:58:35
问题 I am trying to build a sample application using EF7 and mvc 6 in visual studio 2015 pre release. While installing both EF7 and MVC6 using package manager console getting this error. PM> Install-Package EntityFramework.Commands -Version 7.0.0-beta3 -Pre Attempting to gather dependencies information for package 'EntityFramework.Commands.7.0.0-beta3' with respect to project targeting '.NETFramework, Version=v4.5.3' Install-Package : Object reference not set to an instance of an object. At line:1

EF Core - Table '*.__EFMigrationsHistory' doesn't exist

谁说我不能喝 提交于 2019-12-03 10:47:50
问题 I want to stress out that this is .NET Core and the threads about EF 6.0 does not apply to this problem I created my DbContext and added it in DI, however when I do dotnet ef database update -v it does not want to create the migrations table __EFMigrationsHistory . Is there some other command that I should do first or this is a bug of EF Core MySQL adapter? MainDbContext using Microsoft.EntityFrameworkCore; using MySQL.Data.EntityFrameworkCore.Extensions; using Web.Models; namespace Web

How do I delete multiple rows in Entity Framework Core?

冷暖自知 提交于 2019-12-03 10:41:01
I need to delete multiple rows from a database using Entity Framework Core. This code does NOT work: foreach (var item in items) { myCollection.Remove(item); } because I get an error "InvalidOperationException: Collection was modified; enumeration operation may not execute" after the first object. In other words, .Remove removes only one object. Entity Framework Core does NOT have .RemoveRange , so I have no idea how to perform this operation. In order to preserve maximum compatibility with the various database providers, I would prefer NOT to call context.Database.ExecuteSqlCommand("delete

How can I reset an EF7 InMemory provider between unit tests?

安稳与你 提交于 2019-12-03 10:27:07
问题 I am trying to use the EF7 InMemory provider for unit tests but the persistent nature of the InMemory database between tests is causing me problems. The following code demonstrates my issue. One test will work and the other test will always fail. Even though I set the _context to null between tests the second test run will always have 4 records in it. [TestClass] public class UnitTest1 { private SchoolContext _context; [TestInitialize] public void Setup() { Random rng = new Random(); var

How to use EF Core (EF7) with Mysql server?

梦想与她 提交于 2019-12-03 09:50:55
I am developing asp.net 5 (now called ASP.NET Core) on linux. But I cannot connect between EF7 (now called EF Core) and Mysql server. Please tell me any solution that you knew. Thanks. All available providers are listed at https://docs.microsoft.com/en-us/ef/core/providers/ . At time of writing, there are 3 different EF Core providers, two community versions and one official version. UPDATE Sept 15, 2016 MySQL released the first version of an official provider for EF Core. https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore There is also a community version of a MySQL provider https:

The term “Add-Migration” is not recognized

那年仲夏 提交于 2019-12-03 09:19:28
I'm using this MSDN Tutorial to run in VS2015 the command PM> Add-Migration MyFirstMigration -context BloggingContext that ran yesterday successfully but today it's giving the following error that is also pointed out by other users here . I even deleted the Migrations folder from solution explorer and the corresponding db from SQL Express 2014 on Win 8.1 but same error. Even if I run Add-Migration MyFirstMigration I get same error: Add-Migration : The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or

Generic method for updating EFCore joins

丶灬走出姿态 提交于 2019-12-03 08:56:50
One thing that I am finding really tedious with the way EFCore handles many-to-many relationships is updating an entities joined collections. It is a frequent requirement that a viewmodel comes from frontend with a new list of nested entities and I have to write a method for each nested entity that works out what needs to be removed, what needs to be added and then do the removes and adds. Sometimes an entity has multiple many-to-many relationships and I have to write out pretty much the same code for each collection. I think a generic method could be used here to stop me repeating myself but

Entity Framework Core 1.0 DbContext not scoped to http request

孤者浪人 提交于 2019-12-03 08:42:16
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 .UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]); }); //MVC 6 services.AddMvc(); }

Entity Framework Core: How to get the Connection from the DbContext?

試著忘記壹切 提交于 2019-12-03 08:27:43
问题 I am trying the new Entity Framework Core with MySQL Connector. I can get a valid DbContext and write into the database so everything has been setup correctly. I need to get the Connection from the DbContext because I have to test for it at application starting using a connection.Open() inside a try statement. If there is not a valid connection, the console app should try to start MySQL Server and retry. How can I get the Connection from the DbContext ? Before EF6 by context.Connection .

ASP.NET 5 MVC 6 Generic Repository Pattern

百般思念 提交于 2019-12-03 08:26:04
Been looking every where for a tutorial or something. I've been trying to implement my old generic repository pattern for MVC5 into a new MVC6 project. I set up 3 class library's .Core , .Data and .Service , However there's an issue with IDBset , seems my intellisense doesn't like it, I tried to add System.Data and Entity framework 6 but without any luck (cant find it...confusing). After roaming google I decided to ask here, is there a tutorial with the correct way or can someone throw up a very simple MVC6 Generic Repository pattern? I have a feeling the Old method of doing it may have