ef-core-3.1

efcore 3.1 does not support querying with string concatenation?

戏子无情 提交于 2020-05-14 01:23:17
问题 Is there any way to query with EFCore 3.1 by joining multiple fields together with String.Format, or $"{}" or just the traditional "" + "" + ""? I have this code: await this.Db.ACoolDbSet.Where(y => y.Plums + " " + y.Pears == "LOL").ToListAsync(); Plums and Pears are integers. It results in this error: System.InvalidOperationException: 'Null TypeMapping in Sql Tree' Is this expected? This exception was originally thrown at this call stack: Microsoft.EntityFrameworkCore.Query

efcore 3.1 does not support querying with string concatenation?

南笙酒味 提交于 2020-05-14 01:22:09
问题 Is there any way to query with EFCore 3.1 by joining multiple fields together with String.Format, or $"{}" or just the traditional "" + "" + ""? I have this code: await this.Db.ACoolDbSet.Where(y => y.Plums + " " + y.Pears == "LOL").ToListAsync(); Plums and Pears are integers. It results in this error: System.InvalidOperationException: 'Null TypeMapping in Sql Tree' Is this expected? This exception was originally thrown at this call stack: Microsoft.EntityFrameworkCore.Query

How to select top N rows for each group in a Entity Framework GroupBy with EF 3.1

拟墨画扇 提交于 2020-05-09 05:37:08
问题 I need to get top 10 rows for each group in a table with entity framework. Based on other solution on SO, I tried 2 things: var sendDocuments = await context.Set<DbDocument> .Where(t => partnerIds.Contains(t.SenderId)) .GroupBy(t => t.SenderId) .Select(t => new { t.Key, Documents = t.OrderByDescending(t2 => t2.InsertedDateTime).Take(10) }) .ToArrayAsync(); error: System.InvalidOperationException: 'The LINQ expression '(GroupByShaperExpression: KeySelector: (d.SenderId), ElementSelector:

.Net core 3.x Keyless Entity Types avoid table creation

夙愿已清 提交于 2020-04-07 05:11:32
问题 I need to execute a complex sql query in entity framework core 3.1.1, on researching i found out that keyless entity types is the way to go in code first approach. I see lot of documents for dbquery but this is marked as obsolete in .net core 3.x keyless entity types As per Microsoft documentation it says dbquery is obsolete so use dbset approach instead, but with dbset it is trying to create a new table in database. how to disable table generation in keyless entity types while applying

EF Core 3: Configure backing field of navigation property

不羁的心 提交于 2020-03-23 09:56:15
问题 Consider the following class. It tries to protect the access to the _assignedTrays . Actually, it works perfectly, since EF automatically links the backing field _assignedTrays to the property AssignedTrays - by convention (msdn) public class Rack { private List<Tray> _assignedTrays = new List<Tray>(); private Rack() { } public Rack(string rackId) { this.Id = rackId; } public string Id { get; private set; } public IReadOnlyList<Tray> AssignedTrays => this._assignedTrays.AsReadOnly(); public

EF Core 3: Configure backing field of navigation property

*爱你&永不变心* 提交于 2020-03-23 09:56:10
问题 Consider the following class. It tries to protect the access to the _assignedTrays . Actually, it works perfectly, since EF automatically links the backing field _assignedTrays to the property AssignedTrays - by convention (msdn) public class Rack { private List<Tray> _assignedTrays = new List<Tray>(); private Rack() { } public Rack(string rackId) { this.Id = rackId; } public string Id { get; private set; } public IReadOnlyList<Tray> AssignedTrays => this._assignedTrays.AsReadOnly(); public

EF 3.1: Overcome LINQ GroupBy SQL translation problem [duplicate]

[亡魂溺海] 提交于 2020-02-21 06:11:38
问题 This question already has an answer here : Problem with EF OrderBy after migration to .net core 3.1 (1 answer) Closed 27 days ago . In MS SQL Server I have a table that contains a history of calls to contacts (that is another table). Accessed by EF, The Entities are the following: public partial class CallbackHistory { public int HistoryId { get; set; } public int CompanyId { get; set; } public int CallerId { get; set; } public DateTime LastCallTimeStamp { get; set; } public virtual

Problem with EF OrderBy after migration to .net core 3.1

一个人想着一个人 提交于 2020-02-02 05:20:55
问题 Consider this code: _dbContext.Messages .GroupBy(m => new { MinId = m.SenderId <= m.RecipientId ? m.SenderId : m.RecipientId, MaxId = m.SenderId > m.RecipientId ? m.SenderId : m.RecipientId }) .Select(gm => gm.OrderByDescending(m => m.SentAt).FirstOrDefault()); By this I group all dialogues of users by their Id's no matter who sent the message. Then I order messages by SentAt date inside the groups and select one last message out of each dialogue. The thing is that this code worked and more

Problem with EF OrderBy after migration to .net core 3.1

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-02 05:20:28
问题 Consider this code: _dbContext.Messages .GroupBy(m => new { MinId = m.SenderId <= m.RecipientId ? m.SenderId : m.RecipientId, MaxId = m.SenderId > m.RecipientId ? m.SenderId : m.RecipientId }) .Select(gm => gm.OrderByDescending(m => m.SentAt).FirstOrDefault()); By this I group all dialogues of users by their Id's no matter who sent the message. Then I order messages by SentAt date inside the groups and select one last message out of each dialogue. The thing is that this code worked and more