Skip to main content

All Questions

Filter by
Sorted by
Tagged with
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<...
majed tello's user avatar
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....
Tomer Trashman's user avatar
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 ...
Diomedes's user avatar
  • 658
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 ...
capslo's user avatar
  • 45
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 ...
Mohamed Ali Eldin's user avatar
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 =&...
guirms's user avatar
  • 395
-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'...
user3077796's user avatar
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 ...
stack_overflow_nickname's user avatar
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)) ...
greenoldman's user avatar
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>&...
Ezra Bailey's user avatar
  • 1,433
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 = ...
Duc Thang's user avatar
  • 113
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 && ...
khteh's user avatar
  • 3,826
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: ...
Tim Coulter's user avatar
  • 8,907
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.&...
Sami.C's user avatar
  • 711
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 ...
nop's user avatar
  • 6,175
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 ...
Python's user avatar
  • 37
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" ...
asolorzano's user avatar
0 votes
1 answer
394 views

.Net 6 API generic query sorting based on columnName type and order Asc Desc

I'm trying to gain some experience with .net 6 APIs and I have designed a simple app in which the user can sort the data based on a specific column like name or created but now I also want to sort ...
Andreea Elena's user avatar
1 vote
0 answers
365 views

IQueryable difference between .NET 6 and 7

TL;DR: Disable Nullable on entities which are not manually configured using IEntityTypeConfiguration when upgrading. I am currently in the process of upgrading our ASP.Net Core app to .NET 7. In ...
SharpShade's user avatar
  • 2,173
1 vote
2 answers
299 views

System.Exception : The provider for the source 'IQueryable' doesn't implement 'IAsyncQueryProvider'.- xunit and moq

I am working with xunit and moq. I am trying to test FindAsyncTestAsync method return something (not null) using xUnit and Moq. I have instantiated all the required mock repository instances using ...
hanushi's user avatar
  • 1,269
0 votes
1 answer
729 views

No overload for method 'ProjectTo' takes 0 arguments

Error Severity Code Description Project File Line Suppression State Error CS1501 No overload for method 'ProjectTo' takes 0 arguments C# public static async Task<...
User's user avatar
  • 1,355
0 votes
0 answers
162 views

EF Core non-existant column in query, how to rectify?

working my way through an EF core project I have inherited and am quite new when it comes to LINQ/EF core. I'll cut this back to simplify things, and will demonstrate my problem with 4 basic tables. ...
Sami.C's user avatar
  • 711
0 votes
2 answers
619 views

Returning a list inside Linq query from left outer join

I'm new with Linq and hoping for some clarity on a particular query. I have two tables (simplified for demonstration): Table: Customer CustomerId | Name 1 | John Smith 2 | Peter ...
Sami.C's user avatar
  • 711
1 vote
1 answer
56 views

Retrieve IQueryable Result in Public Methods

Is it a valid architeture to declare public methods that retrieve IQueryable results like below : public IQueryable GetData()
Raed Alsaleh's user avatar
  • 1,621
0 votes
1 answer
364 views

EF Core 6: How to use ILazyLoader (it doesn't get injected)

I am trying to use ILazyLoader in my EF Core 6 application. public class IDM_Account { [Key] [StringLength(80)] public string account_id { get; set; } = string.Empty; ...
Razzupaltuff's user avatar
  • 2,279
0 votes
0 answers
170 views

How i can localize enums with EF Core IQueryable projection?

I have asp net Web Api. In get all method I use EF Core IQueryable to retrieve data from DB. Then use project to for map Domain class to response class. Then send this queryable in LoadAsync method ...
Rasim Ismatulin's user avatar
1 vote
1 answer
237 views

How to join two IQueryable queries together? [duplicate]

I want to join two queries into one, how can I do this? For example: Query #1: query = query.Where(q => q.Currency == filter.Currency) Query #2: query = query.Where(n => n.FirstName == filter....
Samvel Yeghikyan's user avatar
1 vote
0 answers
236 views

c# mvc - how do i catch serialization errors that happen after endpoint execution?

i'm using a .NET 6 service. I have controllers marked with [ApiController] and a standard JSON serialization for every response data. also i have a global exception handler registered that converts ...
Kyoshiro Kokujou Obscuritas's user avatar
2 votes
1 answer
2k views

IQueryable.OrderBy is not working with IComparer in EF Core

We have a signature of a method in a IQueryable interface: public static IOrderedQueryable<TSource> OrderBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<...
Viacheslav Kotsiuba's user avatar
1 vote
2 answers
2k views

ASP.NET Core 3.1 / EF Core - Search table column by string name

Currently using: ASP.NET Core 3.1 / EF Core C# Code-first approach Postgres database I'm building a method to support column searching on a table. I need to feed the column name to be searched by ...
Mythprod's user avatar
  • 107
0 votes
1 answer
96 views

CreateInstance inside Extension Method not allowed?

I'm trying to convert my IQueryable<TEntity> results to IEnumerable<TDomainModel> via an extension method. IEnumerable<DeviceModel> resultEntities = _unitofwork....
klau's user avatar
  • 67
0 votes
1 answer
2k views

EF Core IQueryable, Count() efficiency and best practices

I'm writing queries (CQRS pattern) using EF Core 6 that will be consumed by my controller. Besides of the view models I would also like to return some additional data to the client to enable proper ...
toffik325's user avatar
  • 331
0 votes
1 answer
804 views

While querying IQueryable with linq subquery it fail

I just want use an IQueryable fetched from EF Core to filter customers against a filter, in this case the filter is another list of customers. After hours of search I found this and it looks works ok, ...
joe's user avatar
  • 3
4 votes
0 answers
1k views

EF Core difference between AsEnumerable and AsAsyncEnumerable [closed]

Are there any differences in behavior or performance between AsEnumerable, AsAsyncEnumerable and simple iteration over IQueryable in EF Core? // Using .AsEnumerable(); var blogs = context.Posts.Where(...
Anon Anon's user avatar
  • 349
0 votes
1 answer
372 views

The LINQ expression 'p' could not be translated when building custom expression

I have a simple Order class public abstract class Entity { public int Id { get; set; } } public class Order : Entity { public string Description { get; set; } public string DeliveryAddress ...
gzsun's user avatar
  • 329
-1 votes
1 answer
713 views

How to get an IOrderedQueryable<T> after calling Skip() and Take()?

I have a paging class that includes an ApplyFilter() method, which filters rows for the current page. Since paging generally only makes sense in sorted results, this method accepts and returns an ...
Jonathan Wood's user avatar
2 votes
1 answer
415 views

EF Core attaching all entities while adding query on existing query [duplicate]

I have some complex scenarios, but I will show them here as simple. So, my context class is pretty simple: public class AppDbContext : DbContext { protected override void OnConfiguring(...
Dilshod K's user avatar
  • 3,072
0 votes
0 answers
427 views

Entity with some known properties and some unknown at compile time

I am new to C# and Entity Framework. I am creating a project to read all of the rows and columns from a SQL table. When a user connects to a database, a list of tables will be populated to choose from....
Jim's user avatar
  • 3
0 votes
1 answer
754 views

Entity Framework - how to build a query with a list of OR clauses

I'm looking for a way to chain multiple OR clauses in a EF query. Here's an example function, which, when called with an argument int[] containing exactly 2 elements, will create an OR clause with ...
Marko's user avatar
  • 1,582
5 votes
2 answers
6k views

How to pass func expression in LINQ where clause?

This is my Custom filter(Func) to pass in where clause Func<Project,bool> filter = f => { bool filteredContent = true; if (!CreatorId.Equals(0)) filteredContent = f.CreatedBy....
Okasha Momin's user avatar
0 votes
1 answer
132 views

Can you use a dictionary with a let statement in Iqueryable with Entity framework core?

So what I am trying to do is write code that will pick an appropriate personnel based on the data that I have to submit a license to a district board. This code is obfuscated from my actual codebase ...
apinostomberry's user avatar
0 votes
1 answer
267 views

Asp.net core - Entity Framework core - add additional data to a view object while keeping it a Queryable

[EnableQuery] public ActionResult<IQueryable<OurView>> GetInteractionRecordings(int pageNumber) { IQueryable<OurView> ourViews = _dbContext.OurView .Skip((...
JustLooking's user avatar
  • 2,476
0 votes
1 answer
513 views

Build up IQueryable including additional tables based on conditions

I have an issue where we create a complex IQueryable that we need to make it more efficient. There are 2 tables that should only be included if columns from them are being filtered. My exact situation ...
Paul's user avatar
  • 3,133
0 votes
1 answer
845 views

Get and filter multiple classes inside of iqueryable object

I can't figure out how to get this query to work! I need to create iquerialble list of Orders and select only the orders which have StateId from class OrderState equal to desired number Here are my ...
sasko's user avatar
  • 247
0 votes
1 answer
612 views

Sorting data inside of IQueryable object

I have problem with sorting data from IQueryable variable. My code is not in English so I will mock up important code. My Order class has instance of OrderState class, and my OrderState class has an ...
sasko's user avatar
  • 247
0 votes
1 answer
30 views

Can't find single property and navigate related data without IQueryable all properties

I have relational data properties on my objects that I would like to access: public class Person { public ICollection<Address> Addresses { get; private set; } = new Collection<Address>()...
8protons's user avatar
  • 3,929
0 votes
1 answer
222 views

IQueryable extension to group dynamicly by minutes ...and other

I wanted to create an IQueryable extension to allow other developers to group entities by minutely interval but also by custom group key result. My idea was to create a method with the following ...
Steffen Mangold's user avatar
0 votes
0 answers
298 views

EF Core final select projection not generating correct SQL when using UNION

I have 5 tables: Student StudentLocation Location Region RegionDetail In the below code when my IQueryable is without the UNION, the select projection is helping in generating the SQL with the ...
sarvpk's user avatar
  • 59
0 votes
1 answer
121 views

How can I get users group it by time in IQueryable?

I have this query var creature = await _context.Data .Where(x => x.Id.Contains("mono")) .GroupBy(group => new ...
Aziz Alzayed's user avatar
0 votes
1 answer
117 views

how to cast derived BaseModel have isdelete flag in iqueryable, make soft delete repository in entity framework core

why this does not work and how I can fix it, I want to make soft delete/hard delete using one repository public async Task<IEnumerable<TEntity>> GetAsync(Expression<Func<TEntity, ...
Ahmed Fayez's user avatar