entity-framework-core

I need help installing EFCore 3.0 on .net framework 4.8

我的未来我决定 提交于 2021-01-27 23:14:26
问题 Whenever I want to update my EFCore reference to version 3 via NuGet on my NetFramework 4.8 project I get this error. I confirm that I have netcore 3.0 SDK installed on my machine. Could not install package 'Microsoft.EntityFrameworkCore 3.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.8', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the

How to Automatically Map TPH Derived Classes in EF Core?

雨燕双飞 提交于 2021-01-27 23:11:51
问题 By default, EF6 would map a base abstract class and it's derived classes for Table Per Hierarchy (TPH). EF Core no longer follows this logic and requires derived classes to be opted in. The documentation states: By convention, types that are exposed in DbSet properties on your context are included in the model as entities. Entity types that are specified in the OnModelCreating method are also included, as are any types that are found by recursively exploring the navigation properties of other

How to configure Automapper 9 to ignore Object-Properties if object is null but map if not null

跟風遠走 提交于 2021-01-27 22:34:23
问题 I´ve tried a lot, but I can´t find what I´m really looking for. This is my case: I have an EF-Core entity with navigation-properties and a viewModel: public class SomeEntity { public Guid Id { get; set; } public virtual NestedObject NestedObject { get; set; } public DateTime Created { get; set; } public DateTime Modified { get; set; } } public class SomeEntityViewModel { public Guid Id { get; set; } public string NestedObjectStringValue { get; set; } public int NestedValueIntValue { get; set;

Mapping inheritance in EntityFramework Core

孤者浪人 提交于 2021-01-27 21:10:22
问题 I'm using EntityFramework Core, Code First and Fluent Api to define model database, and i've follow situation about strategy of map inheritance: public class Person { public int Id { get; set; } public string Name { get; set; } } public class User : Person { public string UserName { get; set; } public string Password { get; set; } } public class Employee : Person { public decimal Salary { get; set; } } public class Customer:Person { public long DiscountPoints { get; set; } } Business logical

Multiple entities to same DbSet

旧城冷巷雨未停 提交于 2021-01-27 20:06:16
问题 Let's say I have two different classes. They share some properties, but also have some individual ones. public class A { // Shared properties public int Id { get; set; } public DateTime CreatedDtm { get; set; } public string CreatedBy { get; set; } // Individual properties public string PhoneNumber { get; set; } public string EmailAddress { get; set; } } public class B { // Shared properties public int Id { get; set; } public DateTime CreatedDtm { get; set; } public string CreatedBy { get;

Microsoft.AspNetCore.Hosting.Abstractions manifest definition does not match the assembly reference

若如初见. 提交于 2021-01-27 19:37:55
问题 When I run the Entitfy framework core command add-migration MyMigrationName in a class library I get the following error Could not load file or assembly 'Microsoft.AspNetCore.Hosting.Abstractions, Version=1.1.1.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) Funny thing there is no reference in my application to Abstractions. Here is my csproj

Microsoft.AspNetCore.Hosting.Abstractions manifest definition does not match the assembly reference

流过昼夜 提交于 2021-01-27 19:18:09
问题 When I run the Entitfy framework core command add-migration MyMigrationName in a class library I get the following error Could not load file or assembly 'Microsoft.AspNetCore.Hosting.Abstractions, Version=1.1.1.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) Funny thing there is no reference in my application to Abstractions. Here is my csproj

Decimal number in MSSQL table gets rounded although precision is set

橙三吉。 提交于 2021-01-27 14:30:20
问题 My c# object has a decimal property: public decimal LastPrice { get; set; } While processing my object, the decimal value gets set. For example: LastPrice = 0.091354; I modified my DbContext to increase the decimal precision as explained in another stackoverflow post: protected override void OnModelCreating(ModelBuilder modelBuilder) { foreach (var property in modelBuilder.Model.GetEntityTypes() .SelectMany(t => t.GetProperties()) .Where(p => p.ClrType == typeof(decimal) || p.ClrType ==

Do I need to close the DbConnection manually when using ambient transactions with EF Core 2.1?

我是研究僧i 提交于 2021-01-27 13:38:51
问题 EF Core 2.1 introduced support for ambient transactions. The sample creates a new SqlConnection , manually opens it and passes it to the DbContext : using (var scope = new TransactionScope( TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { var connection = new SqlConnection(connectionString); connection.Open(); try { // Run raw ADO.NET command in the transaction var command = connection.CreateCommand(); command.CommandText = "DELETE

What is the most effective way to delete entites that satisfy a condition from a database?

牧云@^-^@ 提交于 2021-01-27 11:28:24
问题 AFAIK, there isn't a direct way to delete entities using a predicate such as DbSet.RemoveWhere(() => {}) I tried a few ways to delete and don't know which is the most efficient way to do it. Could you point me in the right direction? The first and most basic thing I tried is: _context.Users.RemoveRange(_context.Users.Where(u => u.Name.Equals("John"))); which loads the user to the memory before deletion. I don't like this approach. The second way I tried is using the Z.EntityFramework.Plus