86,795 questions
0
votes
2
answers
121
views
How to perform skip and take in Linq with joining multiple tables in optimized way
How to write a linq query that does the same as this SQL statement:
select *
from [dbo].[LitEdit] as le
inner join [dbo].[LitEditJob] as lej on lej.BulkEditId = le.Id
inner join [dbo].[...
1
vote
1
answer
120
views
Using a class property in linq when using Entity Framework
I am trying to use a non-mapped class property in Entity Framework that takes two properties from Entity Framework and checks if one is null, and if it is uses the other property.
Example:
class examp
...
3
votes
2
answers
229
views
How to make reusable linq statements, which can be included as part of a where, select and even order by clause
Imagine the following classes (much simplified version of the real use case):
public class Driver
{
public Int32 Id { get; set; }
public String Name { get; set; }
public String Country { ...
Advice
0
votes
1
replies
33
views
Use Linq to extract a property of objects in a list into a new list
Let's say I have a List<myObject> in which there are 10 instances of myObject.
myObject has two properties: Name and PhoneNumber.
I need a new List<string> taking the Name property from ...
2
votes
1
answer
95
views
CosmosDb ExpressionVisitor (SubtreeEvaluator) fails on Azure, works on local machine [duplicate]
Since a few days, code that has always worked, fails on Azure with an Exception "NotSupportedException: Specified method is not supported.". This Exception occurs when building the query ...
2
votes
3
answers
230
views
Can I use a [ThreadStatic] field with a static local function to avoid creating closures?
Let's say I have this method. Assume Items is an array of strings:
public int GetCount(char c)
{
return Items.Count(x => x.Contains(c));
}
I know that C# creates a closure for Count(x => x....
2
votes
1
answer
120
views
Entity Framework/Linq Get Last Record From List With Condition
I have a list of records, by multiple UserID's.
TableID UserID Status
------------------------
1 3 3
2 4 3
3 3 4
4 4 3
5 5 4
6 ...
0
votes
2
answers
167
views
MRU structure with fixed number of elements, automatically adapting to LINQ queries
I have a folder containing huge numbers of files in many subfolders, and I want to select the files with a name that matches any of a specified list of patterns (regular expressions). My regular ...
7
votes
1
answer
270
views
Difference between Expression.Return and Expression.Goto in C# Expression Trees
I'm experimenting with C# Expression Trees and trying to understand the difference between Expression.Return and Expression.Goto. I can’t create an example where Return and Goto behave differently ...
5
votes
6
answers
208
views
DistinctBy, but preserve the last element of each group of duplicates
I have a list of items that contains duplicates, and I want to keep the last item of each group of duplicates. The native DistinctBy LINQ operator keeps the first item from each group, so it doesn't ...
0
votes
3
answers
131
views
C# Remove Both Duplicate Values from Custom Object Based On Multiple Positive/Negative Values
Working in C# with a custom object that has multiple rows and columns.
I need to remove duplicate records where some (but not all) of the column values match, including positive and negative values of ...
1
vote
1
answer
157
views
How to use expression setters in ExecuteUpdate again in EF Core 10
Microsoft have changed ExecuteUpdateAsync to accept non-expression setters parameter in NET 10. Now it works this way:
await context.Blogs.ExecuteUpdateAsync(s =>
{
s.SetProperty(b => b....
Advice
0
votes
5
replies
106
views
C# & EF Core nullable type return vs not found or multiple database rows
I have the following use case: the database contains a row with a nullable column, and I would like to request only that column value from the database for a single row.
This can easily be done using ...
-5
votes
2
answers
209
views
A list object gets the last five years of an object [closed]
Is there a way I can get the last five years of an object?
I been trying to use Max to get the maximum year and then use range to get all the objects within that range:
using System;
using System.Linq;...
1
vote
1
answer
110
views
How would I use N.EntityFramework.Extensions to insert into another table
I am trying to use the InsertFromQuery() to add data to a SQL table:
await cx.Users
.Where(x => x.Country == "Romania")
.InsertFromQueryAsync("Mailbox", mb => ...