linq-to-entities

LINQ - For each item in select populate value to one unpopulated property

主宰稳场 提交于 2020-02-08 10:46:31
问题 I'm using my Map method to create DTO object from my context class Company and Mapping looks like this: private CompDTO Map(Company company) { return new CompDTO() { Id = company.Id, Title = company.Title, ParentCompanyId = company.ParentCompanyId, }; } CompDTO looks like this: public class CompDTO { public long Id { get; set; } public string Title { get; set; } public long? ParentCompanyId { get; set; } public bool HasChildrens { get; set; } } Here's how I'm calling my Map method : private

Standardizing and Abstracting IQueryable construction with Linq to Entities

十年热恋 提交于 2020-02-08 05:48:24
问题 TL;DR; What is the best way to standardize and abstract IQueryable construction in large data access layers? Are extensions acceptable or encouraged? Background We're using Entity Framework 6 with a Repository pattern as our Data Access Layer. In order to make our data calls more efficient, we've recently started using some structured Data Transfer Objects to force ourselves to only pull from the database what is necessary. For example: We have a dashboard that uses 15 of 500 properties of an

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

CompiledQuery with List.Contains (where…in list) functionality?

狂风中的少年 提交于 2020-01-24 14:29:48
问题 I'm attempting to write a CompiledQuery using Linq-to-Entities that will replace a stored procedure that takes two array (in this case, comma-delimited TEXT) parameters. Essentially, the SQL is be something like this: *Stored Proc definition* @ArrayParm1 TEXT, @ArrayParm2 TEXT -- etc. SELECT [fieldList] FROM someTable WHERE someTable.Field1 IN (SELECT * FROM dbo.fncCSVToTable(@ArrayParm1)) AND someTable.Field2 IN (SELECT * FROM dbo.fncCSVToTable(@ArrayParm2)) dbo.fncCSVToTable creates a

Upgraded to MS Identity Core 2.0 and EF6.1 and login fails: Invalid column name 'Email'

丶灬走出姿态 提交于 2020-01-24 08:40:38
问题 I went to the Manage NuGet Package option and updated all the packages. I'm not using much: Linq-to-EF 6.1 and the packages needed to make MS Identity work. However, something broke because now when I go to log in, I get an error Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'Email'. Invalid column name 'EmailConfirmed'. Invalid column name 'PhoneNumber'. Invalid column name 'PhoneNumberConfirmed'. //and so on The exception looks like this: What might have caused

Entity Framework - Eager load two many-to-many relationships

不羁的心 提交于 2020-01-24 04:20:05
问题 Sorry for this being so long, but at least I think I got all info to be able to understand and maybe help? I would like to load data from my database using eager loading. The data is set up in five tables, setting up two Levels of m:n relations. So there are three tables containing data (ordered in a way of hierarchy top to bottom): CREATE TABLE [dbo].[relations]( [relation_id] [bigint] NOT NULL ) CREATE TABLE [dbo].[ways]( [way_id] [bigint] NOT NULL ) CREATE TABLE [dbo].[nodes]( [node_id]

RIAServices unsupported types on hand-built DomainService

Deadly 提交于 2020-01-23 21:12:54
问题 My EF model was generated from my SQL Server database. I then generated a DomainService for RIAServices against the EF model. One of the entities is called "EntryCategories". The DomainService created this method: public IQueryable<EntryCategories> GetEntryCategoriesSet() { return this.Context.EntryCategoriesSet; } Since my user interface display model looks quite different from the physical model, I decided to write my own DomainService for that and related entities. Yes, I know we are meant

RIAServices unsupported types on hand-built DomainService

淺唱寂寞╮ 提交于 2020-01-23 21:12:41
问题 My EF model was generated from my SQL Server database. I then generated a DomainService for RIAServices against the EF model. One of the entities is called "EntryCategories". The DomainService created this method: public IQueryable<EntryCategories> GetEntryCategoriesSet() { return this.Context.EntryCategoriesSet; } Since my user interface display model looks quite different from the physical model, I decided to write my own DomainService for that and related entities. Yes, I know we are meant

How to turn this Func into an expression?

為{幸葍}努か 提交于 2020-01-23 09:44:27
问题 I am playing around with expression trees and trying to better understand how they work. I wrote some sample code that I'm working with and hopefully someone can help me out. So I have this somewhat messy query: /// <summary> /// Retrieves the total number of messages for the user. /// </summary> /// <param name="username">The name of the user.</param> /// <param name="sent">True if retrieving the number of messages sent.</param> /// <returns>The total number of messages.</returns> public int