86,682 questions
0
votes
0
answers
4
views
How to force a many to many relationship to be queried as OUTER JOIN in Entity Framework
I have this structure in SQL Server:
Look at expanded tables.
CampoAdicionalPorPersona table is a navigation table between Persona and CampoAdicional (many to many relationship).
When I do this query ...
0
votes
1
answer
27
views
Extract a strongly typed expression from a function expression body
I'm trying to write a "relaxed" comparison method which operates on Expressions and is used in Entity Framework. It consists of a chain of Replace() calls and ToLower() to perform an inexact ...
0
votes
0
answers
87
views
Microsoft.Data.SqlClient.SqlError: Incorrect syntax near the keyword 'AND'
This is the error I'm getting when I trye to execute the code.(https://i.sstatic.net/Z2MVQ0mS.png)
Error message: Incorrect syntax near the keyword 'AND'.
StackTrace:
at Microsoft.Data.SqlClient....
0
votes
0
answers
42
views
LINQ: Generic JOIN method [closed]
I'm new to LINQ and would like to know how to build a generic Join Extension method that returns a IQueryable.
I have the childtable and parenttable as a string and i have the primarykey and ...
0
votes
2
answers
74
views
How can I add multiple conditions in a LINQ Select to return values based on an enum?
I'm working on a LINQ query where I need to select values from a data source based on the value of an enum (ConversationRole). I want to return different user IDs based on whether the ConversationRole ...
0
votes
0
answers
56
views
How to exclude records with empty collection in linq query [duplicate]
I have 3 tables in postgres DB (docker postgres:14.1-alpine).
public class House
{
public Guid Id { get; set; }
public virtual ICollection<Flat> Flats { get; set; }
public ...
0
votes
1
answer
70
views
Why EF Core LINQ query works okay for one child and does not work for another one?
So I have a query to get a list of chats with 2 users (including their pictures) and the last message.
An exception is thrown because of that last message sub-query:
"The LINQ expression '...
0
votes
1
answer
35
views
How to avoid materializing a query prematurely in Entity Framework Core
I am working with the ABP Framework using C# and Entity Framework Core, and I have the following query:
public async Task<ListResultDto<GetLinkedOrganizationsDto>> ...
2
votes
2
answers
38
views
Split items to a different group each time a value changes with Linq
I want to split the items using Linq in such way that each time a command type changes the previous items go to a separate group.
I tried to split using GroupBy but it just puts all items with same ...
-2
votes
1
answer
62
views
C# Linq. Join collections by ID
I've got three collections with common key:
var shops = new[] { new { shopId = "1", shopName = "shop1" }, new { shopId = "2", shopName = "shop2" } , new { ...
0
votes
1
answer
39
views
EF Core - Nested property not appearing in Json
I am working on Odata API with .NET. I am facing an issue with the implementation of one of my endpoints. I have a nested array that is not being returned in the JSON response. The /software service ...
0
votes
1
answer
56
views
How to convert join 2 tables with group by into linq
How could I convert this query into Linq in C#?
SQL query:
SELECT *
FROM com.DepartmentPersonnel q1
INNER JOIN
(SELECT dp.DepartmentID, MIN(dp.JobTypeID)JobTypeID
FROM com....
-1
votes
0
answers
96
views
LINQ All() works in one query, not in a similar query
I have been using the following LINQ query successfully to create a dictionary.
searchResults = sharedFiles.Where(x => words
.All(y => x.Value.FileName.ToLower().Contains(y.ToLower())) &&...
0
votes
0
answers
17
views
Receiving Master Data Type as a result
How to get parent model as a result. I want to get MasterData type as a result. i want to use where condition in Attributes but i want to receive Master Data Type as a result
var result= MasterData....
0
votes
0
answers
64
views
Distinct method ony works when modifying string
I am having an issue with the Linq Distinct Method. I have a List of LocationID's
B A01A
B A01A
A A01A
A A01A
A A01A
As you can see, there are only two distinct values here. However, When they are ...
0
votes
1
answer
50
views
Linq - How to query json inside Linq
I have this code:
List<int> cats = new List<int>();
foreach (var cat in ctx.TblCategories)
{
int catCount = ctx.TblProducts
.Where(x => int.Parse( ...
1
vote
1
answer
56
views
Add an aggregate pipeline stage changing to another model or type in MongoDB C# driver
How to add an aggregate pipeline stage that will change the collection model output that the aggregation is being run on?
X/Y question: How to aggregate lookup a document referenced as ObjectId in ...
2
votes
4
answers
189
views
Is it possible to use LINQ to query for elements occuring in a certain sequence?
This is hard to search for as a non-native English speaker, as any search terms I come up with results in lots of questions related to OrderBy(Descending), and not what I am after.
Imagine I have a ...
1
vote
1
answer
44
views
Get child node values from Linq C#
Trying to get values of some child elements in XML, however, when retrieving the values of these elements, they are stitched together.
Also, sometimes the file can have 1 reference number but there ...
0
votes
1
answer
42
views
Why are my GUID type filters returning null?
In my .NET Core application using Entity Framework Core I was using SQL Server but am shifting to SQLite. In SQLite GUID type filters are returning null:
public Guid GetAdminBranchId(Guid companyId)
{
...
-1
votes
0
answers
46
views
Using LINQ query in SQLite, considering GUID as BLOB
I have a .NET Core application where I am using Entity Framework Core.
I was using SQL Server as my main database before, but now I am shifting to a SQLite database.
Here is the simple code that I ...
0
votes
1
answer
39
views
Dynamic Linq GroupJoin Issue
I have a big question about the use of conditions in group joins using Dynamic Linq Query syntax.
I have the following code, which I am using to generate a left join code.
result = result.AsQueryable()...
-1
votes
0
answers
29
views
To search record from database with exact match with same sequence of the search word
How can I search a text from the database with exact match of the sequence of the search word. For example.
In Database has following values of an employee table. In that case I have to get the ...
0
votes
1
answer
47
views
Mock GroupBy method with in-memory database
The following method works perfectly with SQL Server, no issues.
public async Task<IEnumerable<HashRecord>> GetLatestHashes(long jobId, CancellationToken token)
{
var context = ...
1
vote
1
answer
68
views
Linq: Expression not supported: a => new AnonymousType because expression cannot be translated as a field path
I am trying to write a linq query against the Mongo DB C# driver in order to pull back documents from a collection where they do not have a corresponding related record in another collection. A is an ...
1
vote
2
answers
143
views
Shortest way to set a property after FirstOrDefault
Given request.Order type is ColumnName[]. I'm trying to write a one line piece of code equivalent to this incorrect code:
request.Order.FirstOrDefault(x => x.Name == "From").Name = "...
-1
votes
2
answers
82
views
Subgrouping before final grouping [closed]
I have SQL query where I subgroup 4 items before final grouping. Here is the SQL query :
Select DISCIP,
SUM(TOTAL) as TOTAL,
SUM(COMP) as DONE,
SUM(...
-3
votes
1
answer
76
views
Force EF6 to use VARCHAR instead of NVARCHAR in QUERY expressions [duplicate]
Disclaimer - This is both a theoretical and real case question. Legacy and other circumstances makes it real.
The question is:
Can I force EF6 to use VARCHAR instead of NVARCHAR in QUERY expressions?
...
1
vote
0
answers
74
views
Linq ThenInclude and bridge table
ER diagram (do excuse my lack of flowchart skills):
Models:
public class MainObject
{
public int Id { get; set; }
public ICollection<SubObject> SubObjects{ get; set; } = [];
}
public ...
0
votes
1
answer
67
views
SQL -> LINQ - Multiple left joins with null values
I want to convert this sql query to LINQ
left join @categories oc
on OC.course_id = t.course_id
and isnull( t.offlinecategory_id,-1) = isnull(oc.offlinecategory_id,-1)
I tried in ...
0
votes
0
answers
56
views
Convert a LIST specific 2 properties result to a 2D array
I've a list of class containing different type of properties:
public class Test
{
public string grade { get; set; }
public int minVal { get; set; }
public int maxVal { get; set; }
}
...
0
votes
1
answer
41
views
I need to group by datetime but in specific timezone with EF Core and PostgreSQL
I need to group transaction by its CreatedAt property. But in the specific timezone.
Like this
SELECT
SUM("Amount")
FROM
public."Transactions"
GROUP BY
CAST("...
1
vote
1
answer
109
views
C# LINQ OrderBy with an explicit culture returns different results on different .NET versions
I have a list of English and Korean words that I am trying to order so that the Korean words are ordered first, with the English words being ordered last.
This SO post is my exact issue: C# linq order ...
0
votes
1
answer
48
views
How can I use LINQ to filter from a list inside of another list?
Alright, so this is quite hard to explain, but I will do my best.
I have a list filled with books.
All of the books have variables such as Title, publishYear, and Author.
But they also have Genres, ...
0
votes
4
answers
72
views
Is there a way, using Linq, to iterate through a list, check a condition, and send successes and failures to 2 different outputs?
Using Linq, you can iterate through a list, taking all items that meet a condition by using the Where method. However, I have a list in which I want to take all items that meet a condition and do one ...
0
votes
0
answers
24
views
Quirkiness of Blazor Server Apps deployed on Hosted IIS VM on Azure
I am posting this to help me understand what is happening behind the scene with my code in a Blazor Server Application. As mentioned, my Blazor Server App (the App here in after), is, at least to me, ...
0
votes
2
answers
85
views
C# idiomatic `myList.All((item, index) => {...})` [closed]
I've got a List<> in C# and I want to check that all elements of the list meet some condition. This condition depends on the element in the list, as well as that elements index in the list.
It ...
8
votes
1
answer
175
views
.NET 8, EF Core query could not be translated when using a static collection/list as field
I'm curious about the following:
Why is EF Core unable to translate a static readonly ICollection<T> & static readonly IList<T> field into a query when using it inside of a .Contains()...
0
votes
1
answer
38
views
EF Core : Where not working as expected (caching?)
I have this situation:
SQL Server database used with EF Core (code-first strategy).
I have an entity containing a boolean flag called Inactive - with the meaning: when TRUE, this entry is regarded as &...
-2
votes
3
answers
106
views
Only parameterless constructors and initializers are supported
I have a method where I changed the endswith logic with a conditional base as follows from then it starts throwing the exception
public async Task<IEnumerable<CorpTransaction_DTO>> ...
0
votes
2
answers
83
views
LINQ Where logic condition fails to evaluate
.Where(product => productPrices.IsNullOrEmpty() ||
(
product.PProduseCuDimensiuni!.Count > 0 || product.PProduseCuDimensiuni != null
...
0
votes
1
answer
56
views
How to fetch from cosmos db using LINQ records based on certain daterange?
I have a usecase where I need to fetch upcoming birthdays of customers for next 30 days.
We are storing the birthday as datetime in UTC format in cosmos records.
But when I try to fetch using the LINQ ...
-1
votes
1
answer
65
views
How can I have an async response with an IQueryable?
I get the warning message
This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-...
0
votes
0
answers
43
views
LINQ query involving AutoMapper and options from automapper
The problem i am encountering is that : I have a Resolver to get me the price for the current dimension on my current product. But , in my Resolver i am passing in the context.Items dictionary i am ...
1
vote
0
answers
51
views
Write translatable extension methods for use inside of EF Core's .ExecuteUpdate() calls? [duplicate]
I have a number of entities, which inherit from an audit class: AuditableEntity:
public class AuditableEntity
{
public DateTime? LateUpdated { get; set;}
}
...
public class Foo : AuditableEntity ...
0
votes
2
answers
52
views
Update table via linq from viewmodel with list - ASP.NET Core MVC
I have a simple view model with list of items. If I try to update table from this list, I got error about conversion from System.Collections.GenericList to native model class (VykonyVykazyTmpModel). I ...
0
votes
0
answers
27
views
Implementing Many-to-Many Relationship Between Projects and Questions in Razor Pages
When I want to add a question to my project in the project section, I want to be redirected to the questionFilter.cshtml page with the project's ID. After that, I want to add and save the questions I ...
-1
votes
2
answers
94
views
Has EF Core introduced a change in behavior that allows direct entity projection in LINQ queries?
I'm working with EF Core 8 and the MySql provider (Pomelo) in my .NET project. I'm encountering a curious situation where the following code snippet runs without needing Dtos and doesn't produce the ...
0
votes
2
answers
92
views
How can I achieve mentioned Json output from Linq EF in C#
I'm new to ASP.NET MVC and trying to get below Json output of my Linq query of two tables:
{
"data": [
{
"product_id": "1",
"name": "...
1
vote
1
answer
55
views
Microsoft.EntityFrameworkCore - "Cannot resolve symbol 'HasColumnType'"
Note: i could not use the code button for whatever reason, sry.
We currently have installed the following packages:
(.NETStandard 2.0) [old project, but currently we need to stay at this]
Microsoft....