entity-framework-core

EF Core 3 DbQuery equivalent functionality

*爱你&永不变心* 提交于 2020-05-15 19:12:09
问题 In ef core 2.2 I have used DbQuery to map raw sql results to object as following: public partial class AppDbContext{ public DbQuery<SimpleQueryModel> SimpleQM {get;set;} } and then var result=_dbContext.SimpleQM.FromSql(sqlString,params); this wouldn't create any extra table and working just fine. In ef core 3.1 DbQuery is obsolete and telling me to use keyless DbSet instead. I have configured it as following: public partial class AppDbContext{ public DbSet<SimpleQueryModel> SimpleQM {get;set

DbContext.OnConfiguring not getting called and behaving weird in Asp.net core

守給你的承諾、 提交于 2020-05-15 08:57:16
问题 In my asp.net core project i have a ReadingContext class derived from DbContext . According to documentation OnConfiguring should be called for every instance of DbContext that is created. But in my case it is only called when i inspect the instance while debugging. I have a breakpoint inside OnConfiguring but it is not hit even when the method is called. OnConfiguring method. . Instance created but OnConfiguring not called yet . OnConfiguring called on looking into the object but it's

Data Encryption in Data Layer with ASP.NET Core Entity Framework

假如想象 提交于 2020-05-15 02:50:51
问题 I am currently designing a web application where the data needs to be stored encrypted. Planned technologies used: ASP.NET Core API ASP.NET Core Entity Framework MS SQL Server 2012 any Web Frontend Because of the specification, we need to store all data encrypted in the database. Which would be a good approach to achieve this while still be able to use the Entity Framework & LINQ, so the developer does not have to take care of the encryption. Is it possible to encrypt the whole database? 回答1:

The LINQ expression could not be translated and will be evaluated locally

自古美人都是妖i 提交于 2020-05-14 19:27:09
问题 Im getting this WARNING in EntityFramework Core what is wrong? I already set MSSQL Datebase to Case Sensitive. Latin1_General_100_CS_AS var test = await _context.Students .FirstOrDefaultAsync(m => m.LastName.Equals("ALEXANDER", StringComparison.InvariantCultureIgnoreCase)); Microsoft.EntityFrameworkCore.Query:Warning: The LINQ expression 'where [m].LastName.Equals("ALEXANDER", InvariantCultureIgnoreCase)' could not be translated and will be evaluated locally. 回答1: You have to be aware of the

How to adapt IObjectContextAdapter from EF 6 to EF Core

核能气质少年 提交于 2020-05-14 16:24:50
问题 I am trying to port this class to EF core: https://github.com/mehdime/DbContextScope/blob/master/Mehdime.Entity/Implementations/DbContextScope.cs However I am having this issue: Error CS0246: The type or namespace name 'IObjectContextAdapter' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (Mehdime.Entity) and this: Error CS0246: The type or namespace name 'ObjectStateEntry' could not be found (are you missing a using directive or an assembly

Unable to track an entity of type because primary key property 'id' is null

帅比萌擦擦* 提交于 2020-05-13 05:12:14
问题 After I upgraded to Asp.Net Core 3.0 I am getting the following error for my Identity class when attempting to create a user: Unable to track an entity 'User' of type because primary key property 'id' is null. Here User represents my extension of the Identity model. This is the line of code where the error occurs: var result = await _userManager.CreateAsync(user, password); 回答1: This is due to breaking changes in EF Core 3.0 which can be found under this link: https://docs.microsoft.com/en-us

Unable to track an entity of type because primary key property 'id' is null

隐身守侯 提交于 2020-05-13 05:11:00
问题 After I upgraded to Asp.Net Core 3.0 I am getting the following error for my Identity class when attempting to create a user: Unable to track an entity 'User' of type because primary key property 'id' is null. Here User represents my extension of the Identity model. This is the line of code where the error occurs: var result = await _userManager.CreateAsync(user, password); 回答1: This is due to breaking changes in EF Core 3.0 which can be found under this link: https://docs.microsoft.com/en-us

Check if applied migrations match the DbContext?

跟風遠走 提交于 2020-05-13 02:42:51
问题 I want to create a unit test to ensure no developer will commit model changes without the corresponding migration. How do I test that the database matches the DbContext? 回答1: You can leverage some of the lower-level Migrations components to do that: var migrationsAssembly = db.GetService<IMigrationsAssembly>(); var differ = db.GetService<IMigrationsModelDiffer>(); var hasDifferences = differ.HasDifferences( migrationsAssembly.ModelSnapshot.Model, db.Model); Assert.False(hasDifferences, "You

Check if applied migrations match the DbContext?

99封情书 提交于 2020-05-13 02:42:10
问题 I want to create a unit test to ensure no developer will commit model changes without the corresponding migration. How do I test that the database matches the DbContext? 回答1: You can leverage some of the lower-level Migrations components to do that: var migrationsAssembly = db.GetService<IMigrationsAssembly>(); var differ = db.GetService<IMigrationsModelDiffer>(); var hasDifferences = differ.HasDifferences( migrationsAssembly.ModelSnapshot.Model, db.Model); Assert.False(hasDifferences, "You

Blazor concurrency problem using Entity Framework Core

家住魔仙堡 提交于 2020-05-11 11:06:28
问题 My goal I want to create a new IdentityUser and show all the users already created through the same Blazor page. This page has: a form through you will create an IdentityUser a third-party's grid component (DevExpress Blazor DxDataGrid) that shows all users using UserManager.Users property. This component accepts an IQueryable as a data source. Problem When I create a new user through the form (1) I will get the following concurrency error: InvalidOperationException: A second operation