entity-framework-core-2.1

How to uninstall EF Core tables? Or how to remove all migrations ? Or how to call `dotnet ef database update 0` from user code?

别说谁变了你拦得住时间么 提交于 2019-12-29 01:51:30
问题 I'm developing web app and near it small command line application that install ef core tables in the DB. Last can be done calling dbContext.Database.Migrate(); and this works. Now I want to provide unistall option (with this app). But how to remove migrations (means call functionality of dotnet ef database update 0 from my code) ? It could be not one command call (as it was in case with dbContext.Database.Migrate(); ). But snippet with loop through all migrations in migrations assembly and

What could cause `UserManager` to return the wrong user?

本小妞迷上赌 提交于 2019-12-28 19:28:09
问题 Something rather scary is happening on my ASP.NET Core 2.1.0 MVC site. While I was browsing, all of a sudden it shows I am logged in as a different user (who also happens to be browsing the site at that time). I can't pinpoint whether there is a specific use case that triggers this, but this has happened twice now. Navigating to other pages still shows I am logged in as the other user. It even seems I take over the claims of the user I am incorrectly logged in as. My question is: what could

EF Core Migration error: Database 'MyDatabaseName' already exists. Choose a different database name

独自空忆成欢 提交于 2019-12-23 19:43:05
问题 I am running ASP.NET Core 2.1 with EF Core 2.1 application on Windows Server 2016 with SQL Server 2017 Web edition. At the end of public void Configure(IApplicationBuilder app, ... method in Startup.cs I call context.Database.Migrate(); . This applies migrations. Everything works. Now I backup database in my development environment in SQL Server 2016, move MyDatabaseName .bak file to server and restore database MyDatabaseName on server and restart IIS site. When I start application (open

Use a Inline Table-Valued Functions with Linq and Entity Framework Core

孤街浪徒 提交于 2019-12-17 20:36:53
问题 I created an Inline Table-Valued Functions (ITVF) in SQL Server that returns a table of values (query simplified for discussion purposes): CREATE FUNCTION dbo.VehicleRepairStatus() RETURNS TABLE AS RETURN SELECT VehicleID, CurrentStatus FROM VehicleRepairHistory ... Which I can reference in a query: SELECT v.ID, v.Name, r.CurrentStatus FROM Vehicle v LEFT OUTER JOIN dbo.VehicleRepairStatus() r on v.ID = r.VehicleID I'd like to be able to use it in Linq query: var vehicles = await

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 {

Using Always Encrypted of SQL Server from .NET Core 2.1

橙三吉。 提交于 2019-12-11 02:48:50
问题 I am aware that Microsoft has not specified any plan to support Always Encrypted from within Core, yet. However, this is supported by classical .NET Framework (4.5 onward). Our Core 2.1 project's usage of Always Encrypted is limited to two simple queries and we are willing to take alternative routes to use it other than downgrading from Core 2.1. There are many remote ways to solve these problems but they involve remoting (WCF or REST for another classical .NET) or through a Service Fabric

Dynamic audit table creation via Migrations

心已入冬 提交于 2019-12-11 00:59:52
问题 Using .Net Core 2.1 and Audit.NET EF 12.1.10, I'm trying to add a migration that includes the audit tables but when invoking Add-Migration, no audit tables are generated in the migration. I assumed that using the "dynamic" audit will do this automagically. I don't have any audit interfaces-- I am leaving this up to Audit.NET. Below is in my Startup: var serviceProvider = services.BuildServiceProvider(); Audit.EntityFramework.Configuration.Setup() .ForContext<MainDbContext>(config => config

EF Core Group By translation support on conditional sum

╄→гoц情女王★ 提交于 2019-12-10 18:59:06
问题 I was really excited to hear that EF Core 2.1 will be supporting group by translations. I downloaded the preview and started testing it out but found that I am still not getting group by translations in a number of places. In the code snippet below, the query for TotalFlagCases will prevent the group by translation from working. Is there anyway that I can rewrite this so that I can have group by support? Or perhaps another approach that I can take? There are a lot of rows in this table and I

How to UPDATE modified and deleted entities on SaveContext?

余生颓废 提交于 2019-12-10 16:59:29
问题 Goal is to track who had changed and deleted an entity. So I have an entity that implements an interface: interface IAuditable { string ModifiedBy {get;set;} } class User: IAuditable { public int UserId {get;set;} public string UserName {get;set;} public string ModifiedBy {get;set;} [Timestamp] public byte[] RowVersion { get; set; } } Now the code of entity remove operation could look like this : User user = context.Users.First(); user.ModifiedBy = CurrentUser.Name; context.Users.Remove

EF Core 2.1 project Add-Migration NullReferenceException

末鹿安然 提交于 2019-12-06 03:42:01
I am getting a NullReferenceException on a project recently converted to dotnet core 2.1. My EF library project is dotnet core 2.1. Code first migrations. CsvHelper 6.0.2 Microsoft.EntityFrameworkCore 2.1.0 Microsoft.EntityFrameworkCore.Design 2.1.0 Microsoft.EntityFrameworkCore.SqlServer 2.1.0 Microsoft.EntityFrameworkCore.Tools 2.1.0 Output from the add-migration command PM> add-migration -Name MyMigration -Context EscData01Context -Project Data\EscData01 -StartupProject PacmsTri -verbose Using project 'Data\EscData01'. Using startup project 'PacmsTri'. Build started... Build succeeded. C: