ef-core-3.1

How to use GroupBy in an asynchronous manner in EF Core 3.1?

冷暖自知 提交于 2021-01-26 04:11:13
问题 When I use GroupBy as part of a LINQ query to EFCore, I get the error System.InvalidOperationException: Client-side GroupBy is not supported . This is because EF Core 3.1 attempts to evaluate queries on the server-side as much as possible, as opposed to evaluating them on the client-side, and the call cannot be translated to SQL. So the following statement does not work, and produces the error mentioned above: var blogs = await context.Blogs .Where(blog => blog.Url.Contains("dotnet"))

EF6 Query to latest EF Core could not be translated

跟風遠走 提交于 2020-12-15 06:14:38
问题 I have created a query that allows group messages based on the reference number and chose each group's latest record. var list = _context.Messages.Include(m => m.SenderId).Include(m => m.ReceiverId) .Where(m => m.Status != MessageStatus.Archived) .OrderByDescending(m => m.DateAdded) .GroupBy(m => m.Reference) .Select(g => g.OrderByDescending(m => m.DateAdded).FirstOrDefault()).ToList(); Can someone suggest how to convert this to EF Core? 来源: https://stackoverflow.com/questions/64836474/ef6

Are EF Core 3.1 ExecuteSqlRaw / ExecuteSqlRawAsync drop-in replacements for ExecuteSqlCommand / ExecuteSqlCommandAsync?

不打扰是莪最后的温柔 提交于 2020-12-04 18:28:45
问题 Upon upgrade to EFCore 3.1 deprecated warnings appeared: Warning CS0618 'RelationalDatabaseFacadeExtensions.ExecuteSqlCommandAsync(DatabaseFacade, RawSqlString, params object[])' is obsolete: 'For the async execution of SQL queries using plain strings, use ExecuteSqlRawAsync instead. For the async execution of SQL queries using interpolated string syntax to create parameters, use ExecuteSqlInterpolatedAsync instead.' Warning CS0618 'RelationalDatabaseFacadeExtensions.ExecuteSqlCommand

How to prevent a column update in EF Core 3.1?

老子叫甜甜 提交于 2020-07-22 03:55:49
问题 I upgraded from .Net Core 2.2 to 3.1 and this functionality has been deprecated modelBuilder .Entity<Order>() .Property(e => e.CreationTime) .ValueGeneratedOnAddOrUpdate() .Metadata.IsStoreGeneratedAlways = true; I need EF to do the Insert but block the update. Thanks! 回答1: According to the obsoleted property implementation: public virtual bool IsStoreGeneratedAlways { get => AfterSaveBehavior == PropertySaveBehavior.Ignore || BeforeSaveBehavior == PropertySaveBehavior.Ignore; set { if (value

How to prevent a column update in EF Core 3.1?

流过昼夜 提交于 2020-07-22 03:55:29
问题 I upgraded from .Net Core 2.2 to 3.1 and this functionality has been deprecated modelBuilder .Entity<Order>() .Property(e => e.CreationTime) .ValueGeneratedOnAddOrUpdate() .Metadata.IsStoreGeneratedAlways = true; I need EF to do the Insert but block the update. Thanks! 回答1: According to the obsoleted property implementation: public virtual bool IsStoreGeneratedAlways { get => AfterSaveBehavior == PropertySaveBehavior.Ignore || BeforeSaveBehavior == PropertySaveBehavior.Ignore; set { if (value

How to insert graph in Entity Framework with circular dependency

北城以北 提交于 2020-06-28 06:09:11
问题 This is how database structure looks like: Vehicle has lot of CanNetworks and each CanNetwork has lot of ECUs . And that would save perfectly if that was only I have. But, each vehicle also has one special ECU called gatewayECU so problem happens with saving because entity framework core does not know how to handle that scenario. It needs to insert vehicle before inserting ecus, but how to insert vehicle when ecu is not inserted. This is what I tried: ignore (delete, invalidate) gatewayecu

EF core 3.1 can not run complex raw sql query

二次信任 提交于 2020-06-26 06:13:48
问题 The following query was working fine with EF core 2 but EF core 3 would throw error! I even could add some include after this query in EF core 2 which I let go now. query: // just to have an Id var id = Guid.NewGuid(); var resutl = Context.Parties.FromSqlInterpolated($@"WITH mainOffice AS (SELECT * FROM Parties as o1 WHERE (Discriminator = N'Office') AND (Id = '{id}') UNION ALL SELECT o.* FROM Parties AS o INNER JOIN mainOffice AS m ON m.Id = o.ParentOfficeId) SELECT * FROM mainOffice as f")

EF Core 3 DbQuery equivalent functionality

*爱你&永不变心* 提交于 2020-05-15 19:12:09
问题 In ef core 2.2 I have used DbQuery to map raw sql results to object as following: public partial class AppDbContext{ public DbQuery<SimpleQueryModel> SimpleQM {get;set;} } and then var result=_dbContext.SimpleQM.FromSql(sqlString,params); this wouldn't create any extra table and working just fine. In ef core 3.1 DbQuery is obsolete and telling me to use keyless DbSet instead. I have configured it as following: public partial class AppDbContext{ public DbSet<SimpleQueryModel> SimpleQM {get;set