entity-framework

instance of entity type cannot be tracked because another instance with same key value is tracked

跟風遠走 提交于 2020-07-18 04:30:38
问题 I'm using generic repository pattern in asp.net core 2.0 which can not dispose repository object, when I am going to update the entry its updated for one time successfully but when I am trying to update for more then once it throws the following exception: The instance of entity type 'Company' cannot be tracked because another instance with the same key value for {'ID'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is

1-to-1 relationship causing exception: AssociationSet is in the 'Deleted' state. Given multiplicity constraints

北城余情 提交于 2020-07-18 04:16:39
问题 I have set up a 1-to-1 relationship using EF code first following the method prescribed here: Unidirectional One-To-One relationship in Entity Framework My mapping looks like this ... protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Asset>() .HasRequired(i => i.NewsItem) .WithOptional(e => e.Asset) .Map(m => m.MapKey("NewsItemId")); } But when I get this exception ... A relationship from the 'Asset_NewsItem' AssociationSet is in the 'Deleted' state.

Entity Framework Attach/Update confusion (EF Core)

两盒软妹~` 提交于 2020-07-18 04:00:48
问题 As I understand, when "Update" is called, every property within a specific entity is modified. The "Attach" method, on the other hand, starts the entity off in the "Unmodified" state. Then, when an operation takes place on a particular property, that specific property only is modified. So "Attach" is more useful for individual property changes, and "Update" is more useful when you want to update every property in the entity (I may be wrong in this understanding). However, what I don't

Entity Framework Attach/Update confusion (EF Core)

拟墨画扇 提交于 2020-07-18 04:00:17
问题 As I understand, when "Update" is called, every property within a specific entity is modified. The "Attach" method, on the other hand, starts the entity off in the "Unmodified" state. Then, when an operation takes place on a particular property, that specific property only is modified. So "Attach" is more useful for individual property changes, and "Update" is more useful when you want to update every property in the entity (I may be wrong in this understanding). However, what I don't

IQueryable<T> gives different result than a List<T>

独自空忆成欢 提交于 2020-07-15 10:16:21
问题 If I use Select on IQueryable on my entity framework result I'll get 4 items as a result. If I use Select on an IQueryable.ToList() I get all 36 items. Here's code of the function: public ImagesGetModelView Get(int start, int count) { if (count <= 0) count = 9; else if (count > ImageHandler.MaxResult) count = ImageHandler.MaxResult; IQueryable<Image> imagesList = ImagesHandler.FetchRangeScore(start, count) .Where(m => m.Domain == Database.Enums.ImageDomain.Gfycat); //Works using list :( //var

IQueryable<T> gives different result than a List<T>

可紊 提交于 2020-07-15 10:15:51
问题 If I use Select on IQueryable on my entity framework result I'll get 4 items as a result. If I use Select on an IQueryable.ToList() I get all 36 items. Here's code of the function: public ImagesGetModelView Get(int start, int count) { if (count <= 0) count = 9; else if (count > ImageHandler.MaxResult) count = ImageHandler.MaxResult; IQueryable<Image> imagesList = ImagesHandler.FetchRangeScore(start, count) .Where(m => m.Domain == Database.Enums.ImageDomain.Gfycat); //Works using list :( //var

C#: Net Core 3.1 Contains Linq causes Client Side Exception Error [duplicate]

冷暖自知 提交于 2020-07-14 12:08:58
问题 This question already has answers here : EF Core 3 x.Contains() in expression where x is ICollection (2 answers) Closed 5 days ago . The following is throwing a Client Side Exception error in Net Core 3.1 Not sure why, PropertyIdentifier is in Property Entity Data table and class. Does anyone know how to fix? public async Task<IEnumerable<PropertyDto>> GetByPropertyIdentifier(List<string> identifiers) { var properties = await _dataContext.Property .Where(x => identifiers.Contains(x

C#: Net Core 3.1 Contains Linq causes Client Side Exception Error [duplicate]

不羁的心 提交于 2020-07-14 12:06:11
问题 This question already has answers here : EF Core 3 x.Contains() in expression where x is ICollection (2 answers) Closed 5 days ago . The following is throwing a Client Side Exception error in Net Core 3.1 Not sure why, PropertyIdentifier is in Property Entity Data table and class. Does anyone know how to fix? public async Task<IEnumerable<PropertyDto>> GetByPropertyIdentifier(List<string> identifiers) { var properties = await _dataContext.Property .Where(x => identifiers.Contains(x

EF6 Automapper Inheritance/Abstract Class Errors

Deadly 提交于 2020-07-10 11:33:06
问题 I'm building a .NET Web API using Entity Framework 6 with AutoMapper to map entities to DTOs. When I try to introduce an TPH (table per hierarchy) with an abstract base class, I get a very long and very useless (to me at least) error. The error is below, I'm not sure what the actual error is. I've tried Googling various sections of it to no avail. This is my mapping: Mapper.CreateMap<ParentClass, ParentClassDTO>() .Include<ClassA, ClassADTO>() .Include<ClassB, ClassBDTO>(); Mapper.CreateMap

EF6 Automapper Inheritance/Abstract Class Errors

妖精的绣舞 提交于 2020-07-10 11:32:58
问题 I'm building a .NET Web API using Entity Framework 6 with AutoMapper to map entities to DTOs. When I try to introduce an TPH (table per hierarchy) with an abstract base class, I get a very long and very useless (to me at least) error. The error is below, I'm not sure what the actual error is. I've tried Googling various sections of it to no avail. This is my mapping: Mapper.CreateMap<ParentClass, ParentClassDTO>() .Include<ClassA, ClassADTO>() .Include<ClassB, ClassBDTO>(); Mapper.CreateMap