entity-framework-core

.Net Core - Entity Framework Core Migrations - Production

心已入冬 提交于 2020-01-15 05:39:11
问题 After reading many questions here, on Asp.Net's Github (this one comes to mind, ServerFault and SoftwareEngineering, I have decided to ask a question of my own. The Problem Code-First Migrations make live incredibly easy during early development. Staging- or Production-Environments are harder to update, especially during the initial roll-outs which may require frequent updates. Updating the production DB is a lot harder, and automatic migrations are out of the question for a number of very

Entity Framework Core SelectMany then Include

不羁的心 提交于 2020-01-14 08:58:11
问题 I cant seem to figure out how to get EF Core to include / load related objects when using SelectMany. context.MyObject .Where(w => w.Id == Id) .SelectMany(m => m.SubObject) .Include(i => i.AnotherType) Would have thought something like the above would work, however the collapsed SubObject collection has the AnotherObject being null and not included. Been searching for hours. Any help would be appreciated. Thanks 回答1: Would have thought something like the above would work It used to work in

Cannot access a disposed object. A common cause of this error is disposing a context

耗尽温柔 提交于 2020-01-14 08:37:07
问题 I have written a simple application and when I navigate to my edit page the below error pops up. Microsoft.EntityFrameworkCore.Query[10100] An exception occurred while iterating over the results of a query for context type 'app.Models.ApplicationDbContext'. System.ObjectDisposedException: Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your

Error while doing Migrations EF core 2.0, changing Identity id from string to int

十年热恋 提交于 2020-01-14 07:55:29
问题 Scenario: I have received auto generated project in ASP.NET CORE from my colleague. There is auto-generated code for Account/Manage service. This code includes ApplicationUser Class, DBContext and migration folder with 00000000000000_CreateIdentitySchema.cs and 20180323155805_Snapshot.cs. I have been trying to change my User class to have integer id. To do that I added generic to IdentityUser: public class ApplicationUser : IdentityUser**<int>** { } I also had to create ApplicationRole class,

A relational store has been configured without specifying either the DbConnection or connection string to use

不想你离开。 提交于 2020-01-13 19:44:34
问题 I using asp.net vnext and ef7 when i want adding user i getting this error: A relational store has been configured without specifying either the DbConnection or connection string to use. What is this? Consider my app start: using DomainModels; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Routing; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; using Presentation.DataAccessLayer.Context; using Microsoft

Cannot run migration on Entity Framework 7 beta4 in class library package

前提是你 提交于 2020-01-13 12:10:10
问题 I am unable to execute migration command in a class library package. My dnvm version is (from global.json): "sdk": { "version": "1.0.0-beta5-12021" } I'm importing this in my project JSON. "dependencies": { "EntityFramework.Commands": "7.0.0-beta4", "EntityFramework.SqlServer": "7.0.0-beta4", "Microsoft.CSharp": "4.0.0-beta-22816", "System.Collections": "4.0.10-beta-22816", "System.Linq": "4.0.0-beta-22816", "System.Threading": "4.0.10-beta-22816", "EntityFramework.Core": "7.0.0-beta4" },

Cannot run migration on Entity Framework 7 beta4 in class library package

浪子不回头ぞ 提交于 2020-01-13 12:10:10
问题 I am unable to execute migration command in a class library package. My dnvm version is (from global.json): "sdk": { "version": "1.0.0-beta5-12021" } I'm importing this in my project JSON. "dependencies": { "EntityFramework.Commands": "7.0.0-beta4", "EntityFramework.SqlServer": "7.0.0-beta4", "Microsoft.CSharp": "4.0.0-beta-22816", "System.Collections": "4.0.10-beta-22816", "System.Linq": "4.0.0-beta-22816", "System.Threading": "4.0.10-beta-22816", "EntityFramework.Core": "7.0.0-beta4" },

Apply all IEntityTypeConfiguration derived classes in EF Core

廉价感情. 提交于 2020-01-13 11:07:34
问题 Does anyone know of a way or have an implementation to apply ALL classes that derive from IEntityTypeConfiguration<> to the DbContext at runtime? There doesn't seem to be anything built in and loading each one manually via: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.ApplyConfiguration(new Table1Config()) modelBuilder.ApplyConfiguration(new Table2Config()) ... modelBuilder.ApplyConfiguration(new TableNConfig()) } is going to prove rather tedious for a

Apply all IEntityTypeConfiguration derived classes in EF Core

瘦欲@ 提交于 2020-01-13 11:07:32
问题 Does anyone know of a way or have an implementation to apply ALL classes that derive from IEntityTypeConfiguration<> to the DbContext at runtime? There doesn't seem to be anything built in and loading each one manually via: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.ApplyConfiguration(new Table1Config()) modelBuilder.ApplyConfiguration(new Table2Config()) ... modelBuilder.ApplyConfiguration(new TableNConfig()) } is going to prove rather tedious for a

Including only Id of related entity in entity framework core

↘锁芯ラ 提交于 2020-01-13 10:14:09
问题 I am currently developing an API with ASP.NET Core and Entity framework core with npgsql as database provider. I have two Entities and they have a one to many relation. The thing is that I only want to include the Id's of the child entity in the JSON result that the "Parent Controller" returns. These are my entities: public class Meal { public int Id { get; set; } public string Title { get; set; } public string Description { get; set; } public string UserId { get; set; } public User User {