1,477 questions
4
votes
1
answer
117
views
After migration to .NET 9, I have problem with `string.Join` inside Select statement
Previously, when I used .NET 8, I could use String.Join inside the Select statement for an IQueryable, as shown in this code:
var receiveTransactions = await repository.Context.Set<...
-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-...
2
votes
0
answers
32
views
Cannot convert between Data entity and Domain entity IQueryable with Automapper for OData endpoint
I am trying to convert my data entity IQueryable to domain entity IQueryable in my repository class. The Find() method is used by OData to apply filters. The problem is, when I send an OData query ...
0
votes
2
answers
146
views
C# / Entity Framework Core: IQueryable get theoretical rank of score in queryable list of scores without instantiating list
tl;dr, I have a sorted IQueryable of user scores, and I want to get the rank of an attempt (that may or may not be in the IQueryable).
I have a class Attempt that represents an attempt of my videogame....
0
votes
1
answer
97
views
Format for Dynamic IQueryable with Strings and Dates
I'm unsure of the correct format to use string and date as variables in a dynamic IQueryable. With numbers, even though they are passed as strings, it works correctly. However, if I use strings or ...
0
votes
1
answer
70
views
C# .NET Core 6.0 - Using Select when creating the IQueryable is slow, why?
We have a DataTier. Inside this DataTier are models that represent various tables/columns. These models are also associated with their respective DbContext (call it OurDbContext).
public class Foo
{
...
2
votes
0
answers
85
views
How to convert this SQL query to NHibernate IQueryable query?
I have to create a query similar to the one below to paginate a parent-child query:
SELECT v.ProductId, MAX(v.Price) AS Price
FROM Variant v
GROUP BY v.ProductId
ORDER BY Price ASC;
I am using C# ...
0
votes
1
answer
135
views
Guidance On How To Approach Reporting for Razor Page Report
I'm not sure where to begin with this one. I have a database table called Trip. In this table, there is the following info on each row of data:
TripId
ClientName
PickUpDateTime
PickUpLocation
...
0
votes
1
answer
82
views
How to test a method that calls a persistence method returning IQueryable
I read in a few places that it's a good practice for a method that calls the database to return IQueryable because it allows extending queries in services using methods like Select, Where, etc., and ...
0
votes
1
answer
43
views
Include in and condition only if property is not null
I am having lambda expression where I am getting record when all the values are equal in input object and db object
var matchingrecord = (from data in dbContext.TableA
where ...
2
votes
2
answers
156
views
Is it bad to call First() multiple times on an IEnumerable<T> that is actually a List<T>?
I found this method:
public async Task SomeMethod(IEnumerable<Member> members)
{
await DoSomething(members.First());
await DoSomethingElse(members.First());
}
It's being called like ...
0
votes
2
answers
142
views
C# LINQ SUM takes longer than expected
I currently testing for a MVC application and found that one of page seems to take longer.
By measuring times for each execution of lines by lines, I discovered that one of LINQ line takes more than 5 ...
0
votes
0
answers
15
views
How to create a dyamically lambda expression, to feed a Where.() on a List<CustomClass>
Hello i have a List of this custom class of mine (List<ClassePerLifoFifoGestioneInner>).
The class i built like this:
public class ClassePerLifoFifoGestioneInner
{
public int ...
0
votes
0
answers
217
views
How do I use Mapster to Project IQueryable
Good day! I am using Entity Framework 6 and .Net Framework 4.8, in which I have the following entity and DTO:
namespace Assist.Entity.Model
{
public partial class procedure_detail
{
...
1
vote
0
answers
49
views
Querying an entity with property that is converted from List<datetime> to comma separated string. Exception: LINQ expression could not be translated
I am using C# application with Entity Framework version 7.0.4.
I have a building entity that one of its properties should be List, I use value converter to save this as comma separated string as the ...
0
votes
0
answers
58
views
Wanted to perform a Join but keep the IQueryable behavior as is
I have a table named ProductIsNotifyMe for Notify Me functionality on ECommerce application, in which columns would be
StoreID
MemberID
Sku (Product)
LocationId
Unit.
Also I have other products ...
-2
votes
1
answer
182
views
In C# Linq, how to initialize IQueryable or var variable when the type is not known, and linq query returns dynamic fields/object
Original code (no change here)
// present code which need not be changed
public class StatementHelper
{
public List<Xyz> GetStatement()
{
// other code
var result1 = (...
0
votes
1
answer
1k
views
MudDataGrid FilterDefinitions and SortDefinitions in function (ServerData) not working
I have this method to sort and filter dynamically using IQueryiable:
GridState<GreenPaperItem> state = null;
private async Task<GridData<GreenPaperItem>> LoadData(GridState<...
0
votes
0
answers
96
views
Getting The provider for the source 'IQueryable' doesn't implement 'IAsyncQueryProvider' when initializing Test
This is my TestInitialize
[TestInitialize]
public void SetUp()
{
_emailSenderService = new Mock<IEmailSenderService>();
_personRepository = new Mock<IPersonRepository>();
...
0
votes
1
answer
260
views
Entity Framework Core query only work with .ToList()
I'm using .NET Core 7 and Entity Framework Core 7.0.13 and I have the following query:
var test = _context.Set<T>
.AsNoTracking()
.Include(m => m.MachineOperations!
.Where(m =&...
0
votes
3
answers
354
views
C# Filter IQueryable with ToString
I have an IQueryable<SomeObject> query which contains a property Value which is a double.
I want to filter it by a string that has dot thousands separator comma before decimal (european).
I've ...
0
votes
0
answers
40
views
Order IQueryable by grandchild property dynamically
I have an issue with sorting a table. The table columns looks something like this:
ID
Property1: Object
Property2: Object
Property3: int
The table has a sorting options that currently sorts ...
-1
votes
1
answer
1k
views
Testing repository queries of Entity Framework with NSubstitute
I am trying mock my dbContext in order to test my repository queries/filters. I have tried now with in memory database or by mocking the db context. In both cases I can only get it working when i don'...
1
vote
1
answer
288
views
How can I reuse the logic in a Where call while working with Entity Framework Core in .NET?
I am writing a database query using LINQ in .NET and I want to be able to not duplicate the code I put in my Where method calls. All my entities inherit BaseEntity and have in common the properties ...
0
votes
1
answer
72
views
Sorting IQueryable by other List of IDs causes SystemInvalidOperationException
I have a IQueryable of a custom object that contains multiple properties, however, only the ID should be relevant for this.
I made a method that provides me with a List of IDs based on some other ...
0
votes
2
answers
77
views
How to correctly move data from a linked table to the main one in a LINQ query .NET?
Filtering of the query result using "Where" does not work, in which previously one of the fields was replaced with values from the linked table
I have the Items table with another related ...
1
vote
0
answers
27
views
How to apply Expression<Func> value selector in query? [duplicate]
I have such code:
private static IQueryable<Word> filterAndOrderWords(IQueryable<Word> words, string phrase)
{
return words
.Where(it => it.Phrase.ToLower().Contains(phrase))
...
0
votes
2
answers
97
views
Convert Expressions C# with existing Queryable methods
I need to append methods to an existion experssion and combine them into a new resultExpression.
Expression<TSource, IQueryable<TResult>> sourceExpression;
Expression<TSource, int, int, ...
1
vote
2
answers
703
views
EF Core / .NET 6. Using an expression Select on entities
I'm trying to implement a Select with an Expression to keep the object as an IQueryable and selecting into a child navigation collection
Example Code:
public Expression<Func<Item, ItemModel>&...
1
vote
1
answer
97
views
How to convert IQueryable to "Expression<Func" to provide Projection list to NHibernate QueryOver?
Please refer to following code:
using(ISession session = SessionFactory.OpenSession())
{
//Case 1: using Query = works fine.
IList<MasterDto> listMaster = session.Query<MasterEntity&...
0
votes
1
answer
74
views
query syntax LINQ could not be translated to SQL
I have used this query to get the user and his list of followers
var userAndFollowersQuery =
from us in _unitOfRepository.User.Where(i => i.Index == currentUserId)
let fl = ...
0
votes
2
answers
308
views
Entity Framework Core skip and take from the back?
I have the following query:
IQueryable<SellerProductDTO> result = _dbContext.Products
.Where(product => EF.Property<Guid?>(product, "SellerId") != null && ...
0
votes
1
answer
235
views
C# IQueryable .Union reset sorting
I have the following code:
var expressions = new List<IQueryable<Container>>();
var containers1 = containers
.Where(x => EF.Functions.Like(x.ContainerReference1, $"%{message....
1
vote
1
answer
92
views
Why calling .count() on Queryable would make the .ToList() returning 0 rows?
query = query.DistinctBy(q => q.Series.Name)
.OrderBy(c => c.Series.RoleId.Value == (int)Type.Type1 ? 0 : 1)
.ThenBy(c => c.Series.RoleId.Value == (int)Type.Type2 ? 0 : 1)
.ThenBy(...
0
votes
0
answers
208
views
Own implementation of IQueryable Contains method does not work
I'm trying to implement filter to my IQueryable which will checks if list of objects contains some element.
var ratings = repository.GetAll<Rating>()
.AsNoTracking()
....
0
votes
2
answers
83
views
Cast generic within generic IQueryable<T> method
I have a generic IQueryable extension method used with Entity Framework:
public static IQueryable<T> Search<T>(this IQueryable<T> source, ...)
Some uses of this method take in a T ...
0
votes
0
answers
108
views
How to programmatically decompose an EF Core include clause
My EF Core application uses a design pattern that aims to support flexible entity queries, by allowing navigation property loading to be specified at runtime. There are 3 key elements to this pattern:
...
1
vote
0
answers
191
views
Remove column from IQueryable in C# after include [duplicate]
I'm including an entity object inside an other entity object like this:
string[] columnsToRemove = { "Insurance" };
var myQuery = _dataService.GetQuery<Insurance>().Include(i => i....
1
vote
1
answer
401
views
Filter some columns from IQueryable in c#
I need to remove some columns from an IQueryable that include another object using reflection (so i don't want to use anonymous type for create the new IQueryable without a columns).
I've tried this ...
0
votes
1
answer
352
views
IQueryCollection.ToList() combines values unwantedly
My project uses two libraries:
Swashbuckle.ASPNetCore
FluentValidation
Im writing a validator interceptor to do some additional checks that are needed seperately from the validator: MyModelValidator ...
0
votes
1
answer
325
views
Create EF query extension with an Expression
I want to write an Extension method of IQueryable to filter out some entities. This Method should have a parameter of type Expression<Func<T, int>> which is used to filter the entities.
...
0
votes
0
answers
105
views
C# IQueryable returns more data than there is after first call
I have two objects, when I call member functions to retrieve data from the database, order or calling these functions effecting the results.
Whichever function I call the second time, it is returning ...
0
votes
0
answers
2k
views
"The source 'IQueryable' doesn't implement 'IAsyncEnumerable" Only sources that implement 'IAsyncEnumerable'
getting the following error:
The source 'IQueryable' doesn't implement
'IAsyncEnumerable'.
Only sources that implement 'IAsyncEnumerable' can be used for Entity
Framework asynchronous operations.&...
1
vote
1
answer
2k
views
EF Core Union on IQueryable fails with Unable to translate set operation after client projection has been applied
I'm trying to apply .Union on two IQueryable<ReviewAndReleaseDto> queries. Unfortunately, when it reaches the Union call, it fails with:
System.InvalidOperationException: Unable to translate ...
0
votes
1
answer
37
views
EfCore bind method to queryable
I would like to stack some methods
this is what I try to do
private static IQueryable<User> IncludeGroup(this IQueryable<User> query)
=> query.Include(d => d.group);
I ...
1
vote
0
answers
844
views
The provider for the source 'IQueryable' doesn't implement 'IAsyncQueryProvider'
I'm trying to mock some DB access code using simple lists. It generally works except for Async. which causes the error saying the provider does not support Iqueriable. I tries a few suggested ...
1
vote
0
answers
152
views
How to convert C# class into a Async Queryable?
I have a method:
public async Task<int> CountCust(IQueryable<Cust> cust, CancellationToken cancellationToken)
{
......
......
totalCount = await cust.Where(.....).CountAsync(...
0
votes
0
answers
71
views
EF Include doesn't work on a iterative query
I'm working with C# EF 7.0.2, Z.EntityFrameworkPlus and SQL Server. I have a database that could be grown a lot and I want to make it scalable; To do this, I figure out to work with "chunks" ...
1
vote
1
answer
72
views
Contat 2 Lists from different tables into 1 and use AsQueryable()
Attempting to return the below 2 lists into something I can then query against.
var people = (from c in _context.FollowingPeople
select new Models.Following.FollowingModel
{
Id ...
-1
votes
1
answer
1k
views
C# List.AsQueryable() returns System.Collections.Generic.List instead of IQueryable
I have a list of objects List<Student> that I want return as an IQueryable<Student>.
When I try to use .AsQueryable() on the list to convert it to IQueryable<Student> I got a System....