entity-framework-core

Define Entity Framework relationships using foreign keys only by FluentAPI

拜拜、爱过 提交于 2020-03-19 07:58:13
问题 Is any way of defining Entity Framework relations using foreign keys only (no virtual properties of reference type) with FluentAPI (data models should not be changed)? CardDataModel public class CardDataModel { public int CardId { get; set; } } CheckItemDataModel public class CheckItemDataModel { public int CheckItemId { get; set; } public int CardId { get; set; } } 回答1: Yes, it's possible in EF Core. It wasn't in EF6 and below, but now EF Core provides parameterless overloads of HasMany /

Could not load file or assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=1.1.0.0' after upgrading to 1.1.0

心不动则不痛 提交于 2020-03-18 04:52:27
问题 I have a Asp.Net Core project targeting .NET 462 and it was working with Asp.Net Core version 1.0.1. After upgrading to "1.1.0" I got this error: FileLoadException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) project.json "dependencies": { "AspNet.Mvc

Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions using COM

馋奶兔 提交于 2020-03-16 04:29:18
问题 [Recent Note] If it were not for the com-visible aspect, this question would be a duplicate of this question on assembly binding. I had struggled for days because I did not realize that I needed to alter my unit test project as well as the com visible project. If you don't want to read through my struggles realizing this, skip to the last update. [Pre-amble] I feared it may be a bridge to far trying to access a dotnet standard 2.0 library from VB6 via a COM Visible Framework 4.7.2 library,

Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions using COM

喜你入骨 提交于 2020-03-16 04:28:59
问题 [Recent Note] If it were not for the com-visible aspect, this question would be a duplicate of this question on assembly binding. I had struggled for days because I did not realize that I needed to alter my unit test project as well as the com visible project. If you don't want to read through my struggles realizing this, skip to the last update. [Pre-amble] I feared it may be a bridge to far trying to access a dotnet standard 2.0 library from VB6 via a COM Visible Framework 4.7.2 library,

.NET Core 3.1 ChangePasswordAsync Inner Exception “Cannot update Identity column”

一笑奈何 提交于 2020-03-14 11:08:31
问题 I am upgrading a .NET Core Web API from 2.2 to 3.1. When testing the ChangePasswordAsync function, I receive the following error message: Cannot update identity column 'UserId'. I ran a SQL Profile and I can see that the Identity column is not included in the 2.2 UPDATE statement but it is in 3.1. The line of code in question returns NULL, as opposed to success or errors, and is as follows: objResult = await this.UserManager.ChangePasswordAsync(objUser, objChangePassword.OldPassword,

.NET Core 3.1 ChangePasswordAsync Inner Exception “Cannot update Identity column”

久未见 提交于 2020-03-14 11:08:28
问题 I am upgrading a .NET Core Web API from 2.2 to 3.1. When testing the ChangePasswordAsync function, I receive the following error message: Cannot update identity column 'UserId'. I ran a SQL Profile and I can see that the Identity column is not included in the 2.2 UPDATE statement but it is in 3.1. The line of code in question returns NULL, as opposed to success or errors, and is as follows: objResult = await this.UserManager.ChangePasswordAsync(objUser, objChangePassword.OldPassword,

no-build prevents the scaffolding process from being performed?

非 Y 不嫁゛ 提交于 2020-03-05 04:11:10
问题 My textbook says: dotnet ef dbcontext scaffold "Server (localdb)\MSSQLLocalDB;Database=XXX" "Microsoft.EntityFrameworkCore.SqlServer" --output-dir "Models/Scaffold" --context ScaffoldContext --force --no-build --no-build argument prevents the project from being built before the scaffolding process is performed. It is easy to get into a situation where the scaffolding process generates a data model that is out of sync with the rest of the application, such as controllers and views. Entity

Error occurred while access Microsoft.Extensions.HostingServices. Could not parse JSON file

早过忘川 提交于 2020-03-03 11:55:50
问题 I was trying to create a migration for an MVC ASP.NET Core 3.10 project using Visual Studio 2019. I got two errors: An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Could not parse the JSON file. No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If

Error occurred while access Microsoft.Extensions.HostingServices. Could not parse JSON file

戏子无情 提交于 2020-03-03 11:55:32
问题 I was trying to create a migration for an MVC ASP.NET Core 3.10 project using Visual Studio 2019. I got two errors: An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Could not parse the JSON file. No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If

Use “Attach” as an Upsert in Entity Framework Core

房东的猫 提交于 2020-03-03 08:04:00
问题 According to oneunicorn, DbSet.Attach puts all entities in the graph into the Unchanged state. However, entities will be put in the Added state if they have store-generated keys (e.g. Identity column) and no key value has been set. I'm having trouble with the "store-generated keys" part. My database was created in SMSS, and my table has an Id column of type uniqueidentifier, not null. It is the primary key. But how do I tell SMSS it should be store-generated? And will C# find out about that