Questions tagged [linq-to-entities]

This tag is for questions about LINQ to Entities, which means LINQ queries using the ADO.NET Entity Framework. Note that this is different than LINQ to SQL or other LINQ providers.

Filter by
Sorted by
Tagged with
0 votes
0 answers
28 views

Entity Framework subqueries with EXISTS

I have tables Customers (CustomerID, Name, etc.) and Orders (OrderID, CustomerID, etc). How do I select customers that have at least one order in EF, if possible using a subquery? I'm using LINQ. I ...
ekha's user avatar
  • 21
0 votes
2 answers
70 views

How Can I dynamically create an "OR" LINQ query based on input parameter conditions

My problem is a bit more complicated, so I have simplified it with the below example.   Let's say I have a simple list of Integers. I receive two condition input parameters in my function which tell ...
just-an-average-programmer's user avatar
0 votes
1 answer
86 views

Linq Search by Dictionary value

I am trying to search contacts (Objects) that contains a List<Dictionary<string, string>> by a dictionary key and value Below is my Json Array of Contacts [ { "first_name": ...
Asana's user avatar
  • 3
0 votes
1 answer
100 views

LINQ-TO-Entities from SQL

I need some help converting below SQL into LINQ SELECT a.Id FROM ( SELECT s.student_id AS Id, COALESCE(l.city_name, '') AS City, ROW_NUMBER() OVER ( PARTITION ...
Kumar's user avatar
  • 1
0 votes
1 answer
24 views

Select record with < DateTime returns EQUAL value in EF Core 6

I try to select a date field of two records in a MS SQL Server accounting database table. The first record's date is selected by id like this: var lastDate = db.Set<Accounting>().Where(p => p....
Helmut's user avatar
  • 448
0 votes
1 answer
146 views

EF Core 7.0 (PostgresSQL) build IQueryable with RowNumber concept

I have a scenario where one Student (identified by StudentId) has many Courses. Each Course has StudentId(FK) and a Grade (simple text type). I want to build an IQueryable to pull 10 StudentIds (...
sarvpk's user avatar
  • 59
0 votes
1 answer
39 views

How to get the grouped result with an EF query for the following data

I have a table Person with firstname, last name, id. Another table with roles(string) for that person, another table with categories(string). these roles and categories are connected with Occupation ...
Lrn's user avatar
  • 3
0 votes
0 answers
29 views

inline assignment on short hand if in linq select [duplicate]

I have a query where I am taking entity properties and putting them in properties of a DTO. In one property I am grabbing a property from an associated entity and I want three possible results: 1. ...
BlueCardinal's user avatar
2 votes
0 answers
48 views

EF6 generates WHERE clause in unexpected order

I'm using the solution from this answer to form an Expression<Func<Proposal, bool>> object (where Proposal is an entity type in my app), according to the searching criteria input on a ...
Jyunhao Shih's user avatar
  • 1,337
0 votes
0 answers
43 views

Linq Entity Framework 6.0 SQL query with parameters and constants

I need to build an IQueryable<MyClass> in Linq and then obtain the actual SQL query (to be executed by another actor in my system). I get to grab the SQL statement using a method extension like ...
Rollersitch's user avatar
0 votes
1 answer
58 views

EF Core Property/Column Sharing

Original Question I have the following entity I’m trying to get to work with EF Core/NET7, where two properties map to the same column. This way either property could be used in various interfaces ...
Aaron's user avatar
  • 53
0 votes
1 answer
62 views

EF Core CreateDateTime could not be translated

I'm trying to run a linq to entities query in EF Core 6, but I'm receiving an exception saying that System.Data.Entity.DbFunctions.CreateDateTime could not be translated. My goal is to filter a ...
Danilo Silva's user avatar
0 votes
0 answers
60 views

Can I fetch my desired data in one LINQ-to-entities call?

I need a little help in figuring out how I can fetch the location name of the student's home in the below scenario. These are entity framework entities. class Attendance { int Id; DateTime ...
user21996911's user avatar
0 votes
1 answer
106 views

EF 6 foreign key relationship for not compliant naming convention database

I have two tables: Products and Files. The Products table contains a FK column photo_id that references the Files table. The Products table can also reference many files (pdf documents), with ...
Mario Peralta's user avatar
0 votes
1 answer
25 views

EF Query to change IQueryable<T> to a superclass of T

When using inheritence in Entity Framework, OfType<>() to filter a query to only include rows of the specific subclass. The resulting IQueryable is the type of the subclass. Is there a way to do ...
HEDGEWIZARDS's user avatar
0 votes
0 answers
21 views

InvalidOperationException: The LINQ expression could not be translated. - Seemly caused by MaxBy (Or OrderByDescending.Take(1)/.First() [duplicate]

I have a query to get records based on a latest date throwing the exception listed in the title: var thisResult = ctx.Table1 .Join(ctx.Table2, t1 => ...
BlueCardinal's user avatar
1 vote
1 answer
37 views

How to filter products in linq to entities and Entity Framework

I have a table that maps Products to Specs and SpecOptions and SpecUnits: MapProductSpecOptionSpecUnitSpec table: public class MapProductSpecOptionSpecUnitSpec { [Key, Column(Order = 0)] ...
Hooman Limouee's user avatar
1 vote
0 answers
20 views

Linq to Entities Join on two substrings (one via a navigation property) with a Cross Apply (Method Syntax)

Trying to join two tables on two substrings all while performing a cross apply: var thisQuery = ctx.Table1 .Join(ctx.Table2, t1 => t1....
BlueCardinal's user avatar
0 votes
3 answers
62 views

How to achieve the same SQL behavior through LINQ-to-entities

I have the below two entity classes in my application: class Attendance { public int Id {get; set;} public string StudentName {get; set;} // the linked entity public SubjectClass SubjectClass ...
user21996911's user avatar
0 votes
1 answer
57 views

Filter both master and details record and include details in master

Please consider this scanrio: I have a Master table: Id Country -------------------- 1 Ireland 2 Germany 3 Japan and Detials table: Id MasterId SellAmount ...
Arian's user avatar
  • 13k
1 vote
2 answers
295 views

How to convert SQL query values separated comma to list by using entity framework core 7?

I work on asp.net core razor page . I face issue How to convert complicated sql query to entity framework core 7 Exactly I need to convert this SQL statement to LINQ to entity without write SQL ...
ahmed abdelaziz's user avatar
1 vote
0 answers
36 views

Enfity Framework Core : unable to translate a group by query with a left outer join

I'm completely stuck on this simple query, made with Entity Framework Core 6 that should return a list of questions, counting the number of answers for each of them (it's like a forum...): questions = ...
Giox's user avatar
  • 4,893
2 votes
1 answer
97 views

Linq to Entities and update records

I have the following structure: public interface IChainByPreviousId { int Id { get; set; } int? PreviousDeviceId { get; set; } } public class RegisteredDevice : IChainByPreviousId { ...
Oleg Sh's user avatar
  • 8,638
0 votes
0 answers
30 views

Properties not mapping as part of a join?

In a project I'm working on there seems to a mapping going on between the database table and the EF entity, done through configuration. Example: builder.OwnsOne( o => o.ComplexProperty, ...
Casper's user avatar
  • 179
1 vote
2 answers
41 views

Filter model in model records using Entity Framework using C#

I have following classes class Patient { public string fname { get; set; } public string lname { get; set; } public IList<Letter> letter { get; set; } } class Letter { public ...
A. A.'s user avatar
  • 137
0 votes
0 answers
39 views

Entity Framework 6 Ignoring Distinct in SQL Query when Selecting Multiple Columns

I am not seeing the expected sql generated for Linq to SQL with regard to Distinct when selecting multiple columns. In particular the Distinct is being left out of the generated SQL. Strangely, this ...
Eric's user avatar
  • 2,170
1 vote
1 answer
37 views

How to check for the presence of a substring in a string by removing third-party characters?

I have a SQL Server database. In the orders table, I have a column for phone number. At the moment it contains different values like "+38 (453) 454-35-45", "0506070188", "+23 (...
Dmytro's user avatar
  • 33
0 votes
1 answer
30 views

Check if related entity is null before invoking selector using LinqKit

I have a static method that takes an expression containing an entity and a property name of the entity, and a DataSourceResult (this is a Telerik UI for Blazor thing, but it's not important to ...
BlueCardinal's user avatar
0 votes
1 answer
26 views

I want to join three tables using LINQ query at present i am hitting DB three times to get the result

var user = await _userManager.FindByEmailAsync(request.Email); var Menuss = await _context.MenuPermissions .Where(x => x.UserId == user.Id && x.IsHide==false) .Select(x => x....
Towseef Ahmed's user avatar
0 votes
1 answer
47 views

How can I fetch just some include properties from my query and still update it if changes are made?

I have this query var payout = await _dbContext.StripePayouts .Include(p => p.StripeAccount) .Include(p => p.User) .Where(p => p.Id == payoutId) .FirstAsync(); and I only ...
chuckd's user avatar
  • 13.8k
1 vote
3 answers
100 views

Nesting a LINQ query inside a where clause of another query

How would I combine the following two queries into a single query? using (var ctx = ContextFactory.CreateDbContext()) { int parentId = await ctx.MenuEntity.Where(m => m.Title == ...
BlueCardinal's user avatar
0 votes
2 answers
51 views

Find if a date range encompasses current date and if not find latest date in a single linq query

Currently pulling back a list of entities that have different date ranges by year. So StartDate and StopDate for one record in the table is 01/01/2020 and 12/31/2020 respectively. For the next record ...
BlueCardinal's user avatar
0 votes
3 answers
85 views

What's the difference between these 2 EF core queries? And is one better or faster than the other?

Which one is better, faster or more efficient? Or does it not matter in this case? account = await _dbContext.Accounts .FirstOrDefaultAsync(p => p.AccountId == account.AccountId); or account =...
chuckd's user avatar
  • 13.8k
0 votes
1 answer
16 views

Create a method that takes an entity model, a property of an entity mode, and a DataSourceResult as parameter to determine a column width

I am using Telerik UI for Blazor grid and trying to create a method that will take the data brought back from a linq query, look at all the strings in a specific column to find the largest one, ...
BlueCardinal's user avatar
0 votes
1 answer
66 views

'The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.'?

I'm using C# and asp.net. I am trying to separate an email address during a SQL Select query located inside the rest of my C# code. My goal is to display a series of email addresses and each email ...
RMB3030's user avatar
0 votes
1 answer
27 views

Linq order by not working on DateTime after group by into anonymous object

Note: ThisDate is nullable. Trying to get a list of strings for a drop down list ordered like so: 2023 March 2023 February 2023 January And so on. My query: ThisDateList = await ctx.Table1 ....
BlueCardinal's user avatar
1 vote
1 answer
206 views

Concatenate Entity Framework Core models in linq query that are derived from different size varchar columns

Details: using linq method syntax, and database-first Entity Framework Core models. Database is SQL Server. I have 3 tables, the columns from first two tables are of datatype varchar(256) and ...
BlueCardinal's user avatar
-1 votes
1 answer
182 views

Compress in c# and decompress in LINQ To Entities

I have this problem: I'm trying to compress a piece of information coming from "outside" and store into a database table (managed by EF 6.x) with a maximum length of 255 chars. I'm using C#, ...
ff8mania's user avatar
  • 1,593
0 votes
0 answers
88 views

How can get the data from dynamic columns by LINQ To Entities in ASP. Net core C#?

I want to build a dynamic report by Asp.net core -EF-, that is received columns names from user, and then create SQL query depended on these inputs, I wrote this code. But it is return list of columns ...
Arwa's user avatar
  • 1
0 votes
1 answer
60 views

linq-to-entity List/Array .Contains compiles a query using "WHERE (... OR ...)" instead of "WHERE ... IN (...)"

EntityFramework v6.0 IBM.Data.DB2.EntityFramework v10.5 .NET Framework v4 / C# v4.0 (yes, working on upgrading) Example: List<long> myIds = new List<long>{ 12345, 23456, 34567 }; ...
Wayne W's user avatar
4 votes
2 answers
159 views

Get top n values including duplicates with LINQ

Please consider this list: City Value --------------------- City1 10 City2 20 City3 30 City4 40 City5 50 City6 60 If ...
Arian's user avatar
  • 13k
0 votes
0 answers
20 views

Linq to Sql generates code that times out

The SQL being generated by my linq statement is timing out. The manual SQL I write completes in less than a second. I'm trying to write the following SQL statement with linq: SELECT MONTH(s.modified),...
Gargoyle's user avatar
  • 9,680
0 votes
0 answers
100 views

improving linq query with groupby and first()

I have a linq query which I'm grouping and retrieving the first result, where I think the issue is happening and the query timeouts for larger amount of data: This is the query: var result = await ...
Laziale's user avatar
  • 8,037
-1 votes
1 answer
26 views

LINQ to find users without a given role

There is an audit table with which users interacted with the system, I need to build a LINQ query that does the following SQL. The goal of this is to pull back all the rows EXCEPT those made by users ...
Sam Carleton's user avatar
  • 1,369
0 votes
0 answers
33 views

DbArithmeticExpression arguments must have a numeric common type in Entity Framework

I have Entity Framework version greater than 6 as can be seen below and I am getting an error DbArithmeticExpression arguments must have a numeric common type The below LINQ query is generating ...
Kinnan Nawaz's user avatar
0 votes
1 answer
61 views

Linq to SQL: GroupBy() and Max() to get set of data

Consider a table with the following schema Table Schema I would like to fetch data from each Status where category is max In '1' Status, max category is 2, so fetch all rows of category 2 In '2' ...
Developer's user avatar
0 votes
0 answers
20 views

LINQ Join method odd syntax of a colleague, question

A colleague (that left the company) has written the following join: var result = outer .Join(inner, o => new { o.BaseId }, i => new { i.BaseId }, (outer, i) => new { outer,i }) .Select(x =...
TheAnonymousModeIT's user avatar
0 votes
1 answer
312 views

Using LinQ to access multiple tables. What is the correct way to join these tables with LinQ to be the same as SQL Query?

I am trying to access all the tables in the data warehouse that I created for an experimental project using Lin-Q and I just don't seem to understand how to access every table regarding the data ...
Chris Singleton's user avatar
0 votes
0 answers
185 views

EF Core Model Builder exception from duplicate column names

I have a person table and an alias table, and want to return all person where the name matches their name or one of their alias. So I want the person when the name matches and there are no matching ...
Paul Gibson's user avatar
0 votes
0 answers
109 views

Unable to perform Group join in linq in .net6 [duplicate]

I am working on a .net6 framework where querying database through linq to sql. I tried below Group Join in linq to fetch all the Orders against Products but getting an error. Can someone help me get ...
Ronak's user avatar
  • 129

1
2 3 4 5
138