entity-framework-core-2.1

Entity Framework Core: Database operation expected to affect 1 row(s) but actually affected 0 row(s) [duplicate]

≡放荡痞女 提交于 2021-02-18 20:17:16
问题 This question already has answers here : Unable to edit db entries using EFCore, EntityState.Modified: “Database operation expected to affect 1 row(s) but actually affected 0 row(s).” (11 answers) Closed 7 days ago . I am using Sql Server on Linux with EC Core (2.1.0-preview1-final) I am trying to update some data coming from a web Api service (PUT) request. The data (ticket) is passed correctly and gets deserialised into an object (ticket). When I try to update, I use the following code:

Combine BinaryExpression and Expression<Func<dynamic, bool>> in C#

前提是你 提交于 2021-02-16 13:49:08
问题 How can I combine BinaryExpression and Expression<Func<dynamic / T, bool>> ? For example: void AddGlobalFilter<T>(Expression<Func<T, bool>> expr) { var parameter = Expression.Parameter(type, "t"); var member = Expression.Property(filter.Parameter, field); var constant = Expression.Constant(null); var body = Expression.Equal(member, constant); var combine = Expression.AndAlso(body, expr); } I am trying to define global filter for Entity Framework (EF) Core. The problem is I must manually

How to handle huge efcore migrations designer files that is slowing down build and IDE

落爺英雄遲暮 提交于 2021-01-20 15:37:39
问题 I currently have an efcore 2.1 project with about 230 entities and about 350 migrations. Every time i add an efcore migration, a designer file is created. This file is approximately 535 kb and growing (150mb total for alle designer files). This makes the IDE slow and unresponsive, refactoring is a no go, it also makes the build process slower. If i delete all designer files, the build goes down from 110 to 20 seconds, and the IDE gets snappy again. however, once I delete all designer files, i

How to handle huge efcore migrations designer files that is slowing down build and IDE

这一生的挚爱 提交于 2021-01-20 15:35:43
问题 I currently have an efcore 2.1 project with about 230 entities and about 350 migrations. Every time i add an efcore migration, a designer file is created. This file is approximately 535 kb and growing (150mb total for alle designer files). This makes the IDE slow and unresponsive, refactoring is a no go, it also makes the build process slower. If i delete all designer files, the build goes down from 110 to 20 seconds, and the IDE gets snappy again. however, once I delete all designer files, i

Entity Framework Core 2.1 - owned types and nested value objects

笑着哭i 提交于 2020-06-23 07:23:32
问题 I'm learning DDD and the tutorial I'm currently following is implemented using NHibernate, but since my lack of experience with it I've decided to go through the course using EF Core 2.1. However, I'm currently a bit stuck with the following: I have three classes Customer which is an entity and two value objects ( CustomerStatus and inside of it value object ExpirationDate ) - like this: public class Customer : Entity { //... constructor, other properties and behavior omitted for the sake of

The seed entity for entity type 'X' cannot be added because the was no value provided for the required property “..ID”

半世苍凉 提交于 2020-04-12 19:02:02
问题 I'm playing wit EF Core 2.1 Preview 2 . I have troubles with HasData (Seed) method in OnModelCreating(ModelBuilder modelBuilder) My model is simple POCO class that has no annotation. public class Tenant { public int TenantID {get; set;} public string Name {get; set;} } in my DbContext inside OnModelCreating method is DB model defined as modelBuilder.Entity<Tenant>(e => { e.HasKey(m => m.TenantID) .HasName("PK_Tenants"); e.Property(m => m.TenantID) .UseSqlServerIdentityColumn(); e.Property(m =

The seed entity for entity type 'X' cannot be added because the was no value provided for the required property “..ID”

依然范特西╮ 提交于 2020-04-12 18:59:08
问题 I'm playing wit EF Core 2.1 Preview 2 . I have troubles with HasData (Seed) method in OnModelCreating(ModelBuilder modelBuilder) My model is simple POCO class that has no annotation. public class Tenant { public int TenantID {get; set;} public string Name {get; set;} } in my DbContext inside OnModelCreating method is DB model defined as modelBuilder.Entity<Tenant>(e => { e.HasKey(m => m.TenantID) .HasName("PK_Tenants"); e.Property(m => m.TenantID) .UseSqlServerIdentityColumn(); e.Property(m =

The seed entity for entity type 'X' cannot be added because the was no value provided for the required property “..ID”

早过忘川 提交于 2020-04-12 18:58:06
问题 I'm playing wit EF Core 2.1 Preview 2 . I have troubles with HasData (Seed) method in OnModelCreating(ModelBuilder modelBuilder) My model is simple POCO class that has no annotation. public class Tenant { public int TenantID {get; set;} public string Name {get; set;} } in my DbContext inside OnModelCreating method is DB model defined as modelBuilder.Entity<Tenant>(e => { e.HasKey(m => m.TenantID) .HasName("PK_Tenants"); e.Property(m => m.TenantID) .UseSqlServerIdentityColumn(); e.Property(m =

VS Solution Explorer Analyzers exclamation: ef1000 “possible sql injection vulnerability”

ぐ巨炮叔叔 提交于 2020-01-21 06:31:00
问题 Strange message in Solution Explorer. ef1000 "possible sql injection vulnerability" It doesn't prevent compile, no errors, no warnings, no messages in "Errors List". No similar messages in the output on compile... Click doesn't move focus to "vulnerability" line. No referenced file/line related information. But there is context menu with "Delete" button which doesn't work (nothing happens). There are no Analyzers related entries in proj file. Looks like common package references bug. How to

Get List of Entity Models in DbContext Entity Framework Core 2.1

孤街醉人 提交于 2020-01-02 06:26:08
问题 I'm trying to find a way to get a List of all of the entity models in my DbContext. For instance, if I have two models called Customer and Invoice defined in C# which through code-first I created EF entities and a database, how do I now query the DbContext to get a List that has Customer and Invoice in it -- i.e., all of the entities in that context? I want to be able to call a method that returns a List of all the entities -- not the data, just a list of the entities. It seems to me this