entity-framework

Refresh entity framework collection property

无人久伴 提交于 2021-01-28 04:22:27
问题 I'm trying to update parts of my entity framework 6 entities, specifically collections with data from the database. Reading the data from the database the first time is fast so it should be possible to read it again quickly. Disposing the context and creating a new one is fast, but it doesn't work for me, because doing so would lead to losses of information added by the user. So in this case, I have a class called Evaluation, Evaluation has a many-to-many relationship through the class Amount

Double self referencing in Entity Framework

倖福魔咒の 提交于 2021-01-28 03:50:46
问题 When I'm trying to create a migration, Entity Framework throws an error Unable to determine the principal end of an association between the types 'WorkFlowState' and 'WorkFlowState'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations. Code: public class WorkFlowState { public Guid Id { get; set; } public virtual WorkFlowState NextState { get; set; } public virtual WorkFlowState PrevState { get; set; } } What should

With Entity Framework how to create nested objects without one massive query resultset or hundreds of small queries?

99封情书 提交于 2021-01-28 02:17:08
问题 I'm using EF to populate objects which I then interact with in my business layer code. The objects have several levels but let's first simplify it to a typical master-detail example with Order and OrderLine . Let's say I need to retrieve 50 orders each of which has about 100 order lines, and I need all that data. What's the most efficient way of doing this in EF? If I do it like this: var orders = context.Orders.Where(o => o.Status == "Whatever") .Include(order => order.OrderLines) .ToList();

Entity Framework Select Query

大兔子大兔子 提交于 2021-01-28 02:06:35
问题 I have the following classes: public class Seller : Entity { public int SellerId { get; set; } public string Name { get; set; } public ICollection<InventoryItem> InventoryItems { get; set; } } public class InventoryItem : Entity { public int InventoryId { get; set; } public int SellerId { get; set; } public string SellerSku { get; set; } public ICollection<SiteInventoryItem> SiteInventoryItems { get; set; } } public class SiteInventoryItem : Entity { public int Id { get; set; } public int

Double self referencing in Entity Framework

廉价感情. 提交于 2021-01-27 23:31:02
问题 When I'm trying to create a migration, Entity Framework throws an error Unable to determine the principal end of an association between the types 'WorkFlowState' and 'WorkFlowState'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations. Code: public class WorkFlowState { public Guid Id { get; set; } public virtual WorkFlowState NextState { get; set; } public virtual WorkFlowState PrevState { get; set; } } What should

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

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

Setting WHERE condition to use Ids.Contains() in ExecuteSqlCommand()

前提是你 提交于 2021-01-27 20:18:57
问题 I'm using Entity Framework and I want to perform a bulk update. It is way too inefficient to load each row, update those rows, and then save them back to the database. So I'd prefer to use DbContext.Database.ExecuteSqlCommand() . But how can I use this method to update all those rows with an ID contained in my list of IDs? Here's what I have so far. IEnumerable<int> Ids; DbContext.Database.ExecuteSqlCommand("UPDATE Messages SET Viewed = 1 WHERE Id IN (@list)", Ids); I realize I could manually

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;