entity-framework

What is the overhead of Entity Framework tracking?

时光毁灭记忆、已成空白 提交于 2021-01-27 11:50:51
问题 I've just been talking with a colleague about Entity Framework change tracking. We eventually figured out that my context interface should have IDBSet<MyPoco> MyThings { get; } rather than IQueryable<MyPoco> MyThings { get; } and that my POCO should also have all it's properties as virtual . Using the debugger we could then see the tracking objects and also that the results contained proxies to my actual POCOs. If I don't have my POCO properties as virtual and have my context interface using

What is the overhead of Entity Framework tracking?

主宰稳场 提交于 2021-01-27 11:50:21
问题 I've just been talking with a colleague about Entity Framework change tracking. We eventually figured out that my context interface should have IDBSet<MyPoco> MyThings { get; } rather than IQueryable<MyPoco> MyThings { get; } and that my POCO should also have all it's properties as virtual . Using the debugger we could then see the tracking objects and also that the results contained proxies to my actual POCOs. If I don't have my POCO properties as virtual and have my context interface using

What is the overhead of Entity Framework tracking?

佐手、 提交于 2021-01-27 11:49:33
问题 I've just been talking with a colleague about Entity Framework change tracking. We eventually figured out that my context interface should have IDBSet<MyPoco> MyThings { get; } rather than IQueryable<MyPoco> MyThings { get; } and that my POCO should also have all it's properties as virtual . Using the debugger we could then see the tracking objects and also that the results contained proxies to my actual POCOs. If I don't have my POCO properties as virtual and have my context interface using

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

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

本秂侑毒 提交于 2021-01-27 11:23:39
问题 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

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

六眼飞鱼酱① 提交于 2021-01-27 11:22:17
问题 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

EFCore 3.1 - Exists query via Any; Query cannot be translated

孤街醉人 提交于 2021-01-27 11:20:38
问题 We're using EFCore 3.1 and trying to build a query using Exists by means of .Any() which spans 2 properties. var selectionCriteria = someHugeList.Select(sh => new { sh.Id, sh.StatusCode }).ToList() var resultsQry = _myContext.SomeClass .Include(sc => sc.DetailRecords) .Where(sc => selectionCriteria.Any(crit => crit.Id == sc.Id && crit.StatusCode == sc.StatusCode)); var results = await resultsQry.ToListAsync() When running this query (even with a small amount (5 items) of selection criteria

EFCore 3.1 - Exists query via Any; Query cannot be translated

丶灬走出姿态 提交于 2021-01-27 11:20:07
问题 We're using EFCore 3.1 and trying to build a query using Exists by means of .Any() which spans 2 properties. var selectionCriteria = someHugeList.Select(sh => new { sh.Id, sh.StatusCode }).ToList() var resultsQry = _myContext.SomeClass .Include(sc => sc.DetailRecords) .Where(sc => selectionCriteria.Any(crit => crit.Id == sc.Id && crit.StatusCode == sc.StatusCode)); var results = await resultsQry.ToListAsync() When running this query (even with a small amount (5 items) of selection criteria

EFCore 3.1 - Exists query via Any; Query cannot be translated

偶尔善良 提交于 2021-01-27 11:17:09
问题 We're using EFCore 3.1 and trying to build a query using Exists by means of .Any() which spans 2 properties. var selectionCriteria = someHugeList.Select(sh => new { sh.Id, sh.StatusCode }).ToList() var resultsQry = _myContext.SomeClass .Include(sc => sc.DetailRecords) .Where(sc => selectionCriteria.Any(crit => crit.Id == sc.Id && crit.StatusCode == sc.StatusCode)); var results = await resultsQry.ToListAsync() When running this query (even with a small amount (5 items) of selection criteria

How to group records and retrieve only first group with top N records

我只是一个虾纸丫 提交于 2021-01-27 08:23:11
问题 I have the following record set ID BatchID ClientName CreatedDateTime ----------- -------------- --------------- ----------------------- 1 NULL B 2018-02-16 19:07:46.320 2 NULL B 2018-02-16 19:07:46.320 3 NULL B 2018-02-16 19:07:46.597 4 NULL B 2018-02-16 19:07:46.597 5 NULL B 2018-02-16 19:10:10.260 6 NULL B 2018-02-16 19:10:10.260 7 NULL B 2018-02-16 19:21:34.303 8 NULL B 2018-02-16 19:21:34.303 9 NULL B 2018-02-16 19:21:44.780 10 NULL B 2018-02-16 19:21:44.780 11 NULL A 2018-02-16 19:24:35