Questions tagged [linq]

Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages. Please consider using more detailed tags when appropriate, for example [linq-to-sql], [linq-to-entities] / [entity-framework], or [plinq]

Filter by
Sorted by
Tagged with
0 votes
1 answer
20 views

Linq help for multiple joins including an aggregate count from a joined table

This linq query currently works but I hate using subqueries to accomplish this. I know how I would do this in straight SQL but I want to use linq. There has to be a more optimized way using groups ...
Johnny's user avatar
  • 1,141
1 vote
1 answer
51 views

IGrouping with nested properties

I have a IDictionary<Key,Mesh>, where Mesh contains a IEnumerable<Vertex>. Vertex is a struct and contains a VectorInt3 that represents the World Position. I want to write a function/query ...
Raildex's user avatar
  • 3,587
0 votes
0 answers
18 views

find the combinations of attributename and allowedvalues and set IsConflictValue to true if combination matches in C# linq

var inputDto = new List<ChangeAssignmentDto> { new ChangeAssignmentDto { AssignmentId = Guid.NewGuid(), AssignmentHash = Guid.NewGuid(), RoleId = Guid....
matta santhosh reddy's user avatar
0 votes
2 answers
42 views

How to apply a Value to a List of objects where the Value changes every 7 entries in the List?

I have a object, for the purposes of this example, it is quite simple: public class DateEntry { public DateOnly Date { get; set; } public int WeekNumber { get; set; } } I get back a List of 42 ...
Grandizer's user avatar
  • 2,895
0 votes
1 answer
22 views

EF Core Contains unable to be translated

The following query can't be translated, and I can't really understand why something this simple, can't be done! What's causing the problem here, is the contains giving. I need to use a combination of ...
Lasse O's user avatar
  • 349
0 votes
0 answers
20 views

Optimizing VB.NET LINQ Query with multiple string contains?

I'm trying to optimize the following LINQ query, performance is subjective so providing some details below on this aspect. Dim _calls = (From p In db.PhoneLogs.AsNoTracking Where p....
DDulla's user avatar
  • 679
1 vote
1 answer
45 views

How can i make my Query faster using a Groupby with LINQ

I created a Query, it is pretty fast but my table will have 100k+ or even a 1 million records. With 100k rows it takes 5s to load and that is to long. I know using First() is also querying, but i can'...
TwanCS's user avatar
  • 11
1 vote
1 answer
45 views

Multiple instructions with linq select

I have two objects: A containing a list of B objects : A has a property BList which is a list a B objects B has a property A I call a method which returns a list of B elements. Then I want to group ...
Ferdossi's user avatar
0 votes
2 answers
42 views

Initializing Jagged Array with the same non-default value

I am trying to create a jagged array of 10 by 10 using Linq and I want to populate it (for now) all with the same letter (not character). However, I am having trouble figuring out how to populate it ...
moshesilver's user avatar
1 vote
1 answer
56 views

How GroupJoin in C# using LINQ works

I'm trying to learn C#, but I can't understand how groupjoin works in the example I'm seeing in the tutorial. Here the code: namespace ConsoleApp1 { public class Program { static void ...
fabianod's user avatar
  • 510
0 votes
3 answers
109 views

dbContext.SaveChanges() not updating single row as expected in .NET

I have 2 tables: TableA and TableB in MySQL on which I am trying to do some CRUD operations in .NET. I have written a function to insert a new row in TableA followed by updating a single row in TableB....
Krushnal Patel's user avatar
2 votes
2 answers
68 views

Making DefaultIfEmpty return null

I have a class that has 4 fields for nullable doubles: public class myClass { public double? i1; public double? i2; public double? i3; public double? i4; } And I have 4 lists that may ...
Justinas Rubinovas's user avatar
-1 votes
2 answers
52 views

Get Average of TimeSpans with EF Core

I'm using EF Core 7 with Postgres. I need to calculate some stats: public record Job(string Name, DateTime Started, DateTime Stopped); public record Stats(TimeSpan Min, TimeSpan Mean, TimeSpan Max); /...
lonix's user avatar
  • 15.2k
-1 votes
0 answers
61 views

Setting a property of an object returned by ElementAt doesn't seem to do anything

Look at this line: types[i].GenericParameters.ElementAt(j).Description = value; As debugging shows, it doesn't set the Description property of the needed item. You can see the debugging process here: ...
SNBS's user avatar
  • 695
0 votes
2 answers
69 views

Checking and Remove duplicates in a List of Objects C#

I'm looking for a way to check for duplicates and remove them in a list of objects using Linq query expression. First of all, I have two Objects: public class ErrorData { public string Severity { ...
JerryW's user avatar
  • 33
-1 votes
0 answers
35 views

Add Join to existed IQueryable in NHibernate

How to Add Join to existed IQueryable in NHibernate? this is existed query var query = from phoneCall in _session.Query<CRMKernelPhoneCall>() where phoneCall.AnswerQuality != null &&...
Rohullah Rajaee Rad's user avatar
-1 votes
1 answer
48 views

LINQ query in controller showing child as null in Detail view but not in Index view for self reference relationship

I have a self-referencing relationship for the Contacts model, e.g. a contact can have a relationship with another contact. In the Controller GET: Details method I have this code: var contact = await ...
David's user avatar
  • 59
1 vote
1 answer
115 views

How do you populate a List of Lists in C# using LINQ?

Recently I wrote some code akin to the following namespace Foo { public struct Bar { public float val; public Bar(float val) { this.val = val; } } internal class ...
jwezorek's user avatar
  • 9,006
0 votes
0 answers
50 views

LINQ query expression vs using IEnumerable.Where and IEnumerable.Select

I'm coming to C# from Python where we have generator comprehensions such as nums = range(2, 10) evenSquares = (num*num for num in nums if num % 2 == 0) for evenSquare in evenSquares: print(...
joseville's user avatar
  • 743
-1 votes
1 answer
41 views

Error CS1061 when calling LINQ-extension on class implementing additional IEnumerable<>

I need to implement IEnumerable<KeyValuePair<int,IEnumerable<KeyValuePair<DateTime,double>>>> on a class that already derives from Dictionary<int,Dictionary<DateTime,...
draz's user avatar
  • 816
1 vote
1 answer
31 views

The database operation was expected to affect 1 row(s), but actually affected 0 row(s); after _dbContext.SaveChanges();

This is my main class: public class Warehouse { public List<WarehouseRelation> WarehouseRelationList { get; private set; } = new List<WarehouseRelation>(); public void ...
merve şahinoglu's user avatar
1 vote
0 answers
83 views

The LINQ expression OrderBy DateTimeOffset.DateTime could not be translated

I have a .NET Core project in which I have implemented this GraphQL query. The query works correctly, but the sorting by date is not working. [UsePaging(MaxPageSize = 200, IncludeTotalCount = true)] [...
AmD's user avatar
  • 429
0 votes
3 answers
83 views

The LINQ expression could not be translated error

I have a database with two tables, Requests and Authorities. Authorities has a column called AuthorityOf containing a string such as "AAAA" and each request in the Requests table has a ...
Mikael's user avatar
  • 11
0 votes
0 answers
29 views

Linq nested DTO expression

I am new to Linq and I need help on the below. I have the following data structure. DTOData which is a list Inside this is have tables and this is also list Inside tables, I have 2 fields Name and DOB....
Ramesh's user avatar
  • 1
0 votes
1 answer
68 views

EF Core One-to-Many Linq query

I have a one-to-many relationship between two entities, and need to query a combination of those two entities. The one is a File model: public class FileMetadata { [Key] public ...
Divan's user avatar
  • 342
0 votes
1 answer
43 views

.NET EF Core Automapper ProjectTo filtering is not working

I have the following piece of code var taskDTOs = await _repo.GetQueryable<TaskStatus>() .Where(s => s.Tasks.Any(t =>t.CompanyId == _userContext.CompanyId && t.UserId == ...
Nour Mawla's user avatar
0 votes
2 answers
137 views

Using LINQ, group list of object combination inside another list of objects

Update: Change class name as ComboProduct and Product for clear public class Product { public string Name {get; set;} } public class ComboProduct { public int Id; public List<Product&...
Khanh Nguyen Van's user avatar
0 votes
1 answer
61 views

Mimicking SQL Outer apply with LINQ

I'm having a bit of the trouble with translating following stored procedure to into LINQ. SELECT DISTINCT a0.[recid] AS 'Id' ,a0.[latitude] AS 'Latitude' ,a0.[longitude] AS 'Longitude' ,...
Mate Abulashvili's user avatar
0 votes
1 answer
27 views

EF Core lookup to diffrent entities based on field value

In my model, i have entity with field that can join (LookUp) different table basing on value of an other field (Document_Type in my example). example : I have PurchaseLine entity it's can have ...
Ait Yahia Idir's user avatar
0 votes
2 answers
65 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
63 views

Operator <= cannot be applied to operands of datetime and dateonly

I have some C# code which im porting over to SQL. The C# code compiles and works as expected. I try to copy it over to LinqPad to see what SQL is generated but i get the error "operator <= ...
KeithViking's user avatar
6 votes
2 answers
242 views

How to group a square grid diagonally

I have a string of boolean values which represent a square grid. 0100001110000100 I am trying to write validation routine which checks the grid diagonally to ensure that there are no diagonal lines ...
Eval Knievel's user avatar
0 votes
3 answers
57 views

Trying to figure out a c# linq for the list of objects which can be tagged with multiple categories. Get the category with the associated objects

list of entities tagged categories entity1 (cat1, cat2, cat3) entity2 (cat2, cat4, cat5) entity3 (cat1, cat3, cat5) entity4 (cat2, cat3) entity5 (cat1, cat4, cat5) Class Entity { ...
cshaprcoder101's user avatar
0 votes
1 answer
45 views

Where id of object in list matches list of id set property to true

I'm trying to populate a dropdown list with pre-selected options. I populate this list with a list of SelectListItems which allow you to set their "Selected" property to true. However I want ...
beeeeeeeeeen's user avatar
1 vote
1 answer
64 views

Retrieving key/identifier of array of JSON objects before iterating through that array via NewtonSoft Linq

Is there a method of retrieving the 'key' of an array of JSON objects before iterating through said array? I'm trying to associate the values in each array with the associated key, and I'm having ...
Hazeron's user avatar
  • 11
0 votes
1 answer
30 views

Returning a filtered list of items from where the ID is in a list from another array of matching guids

After a bit of help to get the a list filtered using another list of items. Ordinarily I'd of coded around this in SQL, but I need to try to get this working in .NET. I have a list of Roles, and each ...
Gavin Clayton's user avatar
0 votes
2 answers
74 views

LINQ Query for an old ADO.NET Query

I am not used to writing JOIN statements using LINQ. I am trying to convert this old query into LINQ Lambda syntax and struggling to understand how to go about it. Any help would be greatly ...
hillcountry99's user avatar
1 vote
2 answers
51 views

Is there a better way to get full row of calculated group by using LINQ

This question is a further question to https://stackoverflow.com/questions/157786/how-do-i-get-the-max-row-with-a-group-by-in-linq-query. Besides the max value and the group key, I need the every ...
Rob Lao's user avatar
  • 1,568
0 votes
1 answer
29 views

I have this error when add column to database dbml file linq

This this my dbml file in the asp.net mvc core 5 When i try to create a new entity for my modified table and then drag/cut the new property from the new entity to my old one , I have this error in ...
Hoàng's user avatar
  • 31
0 votes
0 answers
48 views

How to use EXISTS and IN with the subquery in Linq

Could you please help me to convert this to Linq where we have EXISTS and IN for sub query. Select * From laqTasks where siteid=1 and Exists(Select 1 from laqTasks where room=1) and duty=1 and Room ...
shanthakumar n's user avatar
-1 votes
1 answer
72 views

Using in inside linq where condition [duplicate]

select * from laqTasks t where t.Duty in (1, 2, 3) How to use in inside the Linq, should I use contains. var UpdateLaqTasks = dbContext.Tasks.SingleOrDefault (p => p.Room == roomId &...
shanthakumar n's user avatar
2 votes
1 answer
100 views

LINQ for "Outer Apply" / "Left Outer Join" kinda Query for PostgreSQL

I have a problem with my linq query, it performs really slow. And when I debug and see the translated query, I see what the problem is. My LinQ isn't really make the query I want. Here's the LinQ I've ...
James's user avatar
  • 451
0 votes
1 answer
85 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
80 views

Variable changing on its own?

Just look at this GIF — can you see a statement that changes the value of j? https://imgur.com/a/tjDmstd Here's my code, if needed: for (int j = 0; j < types[i].GenericParameters.Count(); j++) { ...
SNBS's user avatar
  • 695
1 vote
1 answer
46 views

EF Core expression with object instead of generic parameter

I have a method which searches for an entity, and optionally loads navigation properties: public async Task<Person?> FindPerson<TProperty>(string name, params Expression<Func<Person, ...
lonix's user avatar
  • 15.2k
0 votes
1 answer
45 views

Client evaluation in top-level EF Core projection

Suppose I perform a query and project into an anonymous type; that would perform evaluation on the server: var people = await context .People .OrderBy(x => x.Name) .Select(x => new { x.Id, ...
lonix's user avatar
  • 15.2k
0 votes
0 answers
57 views

How to resolve error: "value cannot be null parameter name Response" in Linq?

Getting this error Value cannot be null. Parameter name : response in LINQ while executing the statements shown here. Please let me know. Error is not occurring if I comment out the filterItem ...
Prithvi's user avatar
0 votes
2 answers
67 views

In Linq, How to get list of parents that their children have a special age and other childern remove too?

I have two models: Parent and Child public class Parent { public int ID { get; set; } public string Name{ get; set; } public virtual ICollection Children { get; set; } } public class ...
NedaM's user avatar
  • 91
0 votes
2 answers
55 views

Linq query to check list contains empty string then check for null

I have a list that may or may not contain an empty string. In the case that it does I want to create a linq query to check for nulls in a where clause while also checking for other values in the list ...
TheProgrammer's user avatar
0 votes
1 answer
42 views

TakeWhile LINQ expression couldn't be translated

SQLite database table consists of four columns: Id = table.Column<Guid>(type: "TEXT", nullable: false), Date = table.Column<DateTime>(type: "TEXT", nullable: false), ...
Pozzi Userpic's user avatar

1
2 3 4 5
1727