entity-framework-core

Database operation expected to affect 1 row(s) but actually affected 0 row(s)

放肆的年华 提交于 2020-08-27 06:06:50
问题 I'm trying to insert records in two tables, but getting the exception. Could you please help me to resolve the issue. First I tried the below code. await _testRepository.InsertAsync(test); await _xyzRepository.InsertAsync(xyz); Then I tried this code, But nothing is working for me. try { var test = new Test(); using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew)) { int? tenantId = _unitOfWorkManager.Current.GetTenantId(); using (_unitOfWorkManager.Current.SetTenantId

Update parent and child collections on generic repository with EF Core

自古美人都是妖i 提交于 2020-08-21 05:35:21
问题 Say I have a Sale class: public class Sale : BaseEntity //BaseEntity only has an Id { public ICollection<Item> Items { get; set; } } And an Item class: public class Item : BaseEntity //BaseEntity only has an Id { public int SaleId { get; set; } public Sale Sale { get; set; } } And a Generic Repository (update method): public async Task<int> UpdateAsync<T>(T entity, params Expression<Func<T, object>>[] navigations) where T : BaseEntity { var dbEntity = _dbContext.Set<T>().Find(entity.Id); var

Update parent and child collections on generic repository with EF Core

纵然是瞬间 提交于 2020-08-21 05:34:09
问题 Say I have a Sale class: public class Sale : BaseEntity //BaseEntity only has an Id { public ICollection<Item> Items { get; set; } } And an Item class: public class Item : BaseEntity //BaseEntity only has an Id { public int SaleId { get; set; } public Sale Sale { get; set; } } And a Generic Repository (update method): public async Task<int> UpdateAsync<T>(T entity, params Expression<Func<T, object>>[] navigations) where T : BaseEntity { var dbEntity = _dbContext.Set<T>().Find(entity.Id); var

Filtering on Include in EF Core

空扰寡人 提交于 2020-08-20 11:23:12
问题 I'm trying to filter on the initial query. I have nested include leafs off a model. I'm trying to filter based on a property on one of the includes. For example: using (var context = new BloggingContext()) { var blogs = context.Blogs .Include(blog => blog.Posts) .ThenInclude(post => post.Author) .ToList(); } How can I also say .Where(w => w.post.Author == "me") ? 回答1: Finally, this feature has been implemented starting with EF Core preview version 5.0.0-preview.3.20181.2 and will be GA in EF

Group join in EF Core 3.1

冷暖自知 提交于 2020-08-19 07:29:29
问题 I am trying to group join in EF core 3.1 the problem it returns Processing of the LINQ expression 'DbSet failed. This may indicate either a bug or a limitation in EF Core my code is like this var employees = await (from enrollment in RepositoryContext.Enrollments join allowance in RepositoryContext.Allowances.Include(y=>y.AllowanceType) on enrollment.EmployeeId equals allowance.EmployeeId into allowances select new { enrollment, allowances } ).AsNoTracking().ToListAsync(); the allowances is