entity-framework-core

Attaching an entity with a mix of existing and new entities in its graph (Entity Framework Core 1.1.0)

回眸只為那壹抹淺笑 提交于 2019-12-12 08:32:12
问题 I have encountered an issue when attaching entities holding reference properties to existing entities (I call existing entity an entity that already exists in the database, and has its PK properly set). The issue is when using Entity Framework Core 1.1.0. This is something that was working perfectly with Entity Framework 7 (the initial name of Entity Framework Core). I haven't tried it neither with EF6 nor with EF Core 1.0.0. I wonder if this is a regression, or a change of behaviour made on

ASP.NET 5 MVC 6 Generic Repository Pattern

无人久伴 提交于 2019-12-12 07:38:24
问题 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

Entity Framework Core: Fail to update Entity with nested value objects

≯℡__Kan透↙ 提交于 2019-12-12 07:17:49
问题 I have an entity that has a value object and this value object has another value object. My issue is that when updating the entity along with the value objects, the entity with the parent value object get updated but the child value object didn't. note, i used latest version of Entity Framework Core 2.1.0-rc1-final this is the parent entity Employee public class Employee : Entity { public string FirstName { get; private set; } public string LastName { get; private set; } public string Email {

“Build failed” on Database First Scaffold-DbContext

老子叫甜甜 提交于 2019-12-12 07:09:37
问题 I'm trying to generate classes from a database (EntityFramework's database first approach). For convenience, I'm more or less walking along with this tutorial: https://docs.efproject.net/en/latest/platforms/full-dotnet/existing-db.html I'm at a point where I am running the equivalent of this line of code in the Visual Studio Package Manager Console: Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -Verbose

In what files are the Data Model and Schema declared in ASP.NET Core projects?

白昼怎懂夜的黑 提交于 2019-12-12 07:03:14
问题 Going by this answer, I know that an ASP.NET Core project must have a data model and a database schema, if it has a database. For months, I thought the data model resided in a Context class that inherited from DbContext. But I've come cross a tutorial that says this class is where the Schema lives. Where does the Data Model and Schema get declared for ASP.NET Core projects? 回答1: It uses EF Core (an O/RM). It uses metadata mapping to define that database schema based on the domain model. 来源:

Save changes to child class properties using base class query with Entity Framework TPH patten

血红的双手。 提交于 2019-12-12 06:32:35
问题 I have a simple TPH hierarchy: public abstract class UserAccount { public string FirstName { get;set; } } public class InterpreterAccount : UserAccount { public string PhoneNumber { get;set; } } and in DbContext: //....... public DbSet<UserAccount> UserAccounts { get; set; } public DbSet<InterpreterAccount> InterpreterAccounts { get; set; } This code works (saves both FirstName and PhoneNumber to DB): var account = _context.InterpreterAccounts.Single(i => i.Id == id); account.FirstName =

How to resolve the dependency on Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.Tools?

£可爱£侵袭症+ 提交于 2019-12-12 06:25:00
问题 I am trying to create an application using Microsoft SQL Server database using Entity Framework Core. This is what I have done so far Step 1: From Nuget Package manager I have installed: Install-Package Microsoft.EntityFrameworkCore.SqlServer Step 2: From Nuget Package manager I have installed (for Entity Framework commands) : Install-Package Microsoft.EntityFrameworkCore.Tools –Pre And my project.json looks as under { "version": "1.0.0-*", "buildOptions": { "emitEntryPoint": true },

EF Core: inherited entities has navs to same table

我的梦境 提交于 2019-12-12 06:16:43
问题 public abstract class Base { public Guid Id { get;set; } public Navigation Nav { get;set; } public string NavID { get;set; } } public class ConcreteFirst: Base { } public class ConcreteSecond: Base { } public class Navigation Nav { public string NavID { get; set; } public ICollection<ConcreteFirst> ConcreteFirsts { get;set; } public ICollection<ConcreteSecond> ConcreteSeconds { get;set; } } //OnModelCreating builder.Entity<Base>().Ignore(b => b.Nav); builder.Entity<ConcreteFirst>() .HasOne(c

Deploying ASP.NET Core Web App + SQL from a repository

纵然是瞬间 提交于 2019-12-12 04:35:08
问题 I'm working on this tutorial, Getting Started with ASP.NET Core and Entity Framework Core using Visual Studio, and I'd like to deploy it to Azure from a GitHub repository. Using "Web App + SQL" in Azure I can deploy it successfully once, but when I make a change to the database and redeploy I get the error, "Applying existing migrations may resolve this issue..." So is there some way I can trigger a database update when the app is redeployed with a new migration present? Just a note, I know

Why is dotnet ef not able to create a database against SQL Server Express?

早过忘川 提交于 2019-12-12 04:34:00
问题 I have gone through this ASP.Net MVC Core tutorial at: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/working-with-sql. And I am able to use dotnet migrations to create the database against the localDb with this connection string in the appsettings.json file: { "ConnectionStrings": { "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-MvcMovie-3005e0f3-42f4-4163-94cc-f794a05e8b91;Trusted_Connection=True;MultipleActiveResultSets=true" } Now I want to