score:1
Accepted answer
var appusers = await _masterdbcontext
.users
.asnotracking()
.include(x => x.usercustomers)
.where(user =>
!user.isdeleted
&& user.usercustomers
.any( x => x.customerid == tenant.id ) )
.distinct()
.select(appuserdto.projection)
.todatasourceresultasync(request.gridoptions, cancellationtoken: cancellationtoken);
score:0
var filtered = _masterdbcontext.users
.select(appuserdto.projection)
.where(user => !user.isdeleted && user.usercustomers.any(x => x.customerid == tenant.id && x.userid == user.id));
var query =
from d in filtered.select(d => new { d.id }).distinct()
from u in filtered.where(u => u.id == d.id).take(1)
select u;
var appusers = await query.todatasourceresultasync(request.gridoptions, cancellationtoken: cancellationtoken);
Source: stackoverflow.com
Related Query
- EF Core rewrite the query in a form that can be translated after upgrading
- EF Core how to rewrite the query in a form that can be translated
- Entity Framework Core 3.1 - Linq - Could not be translated. Either rewrite the query in a form that can be translated
- The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation EF Core 3.1
- The LINQ expression could not be translated. Eiither rewrite the query in a form that can be translated
- Entity Framework Core 3.1.1 Where query could not be translated. Either rewrite the query in a form that can be translated,
- System.InvalidOperationException: 'The LINQ expression could not be translated. Either rewrite the query in a form that can be translated
- The LINQ expression 'Expression' could not be translated. Either rewrite the query in a form that can be translated
- Orderby could not be translated. Either rewrite the query in a form that can be translated
- Th linq query could not be translated. Either rewrite the query in a form that can be translated .NETCore
- The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation
- Which conditions must a query meet so that it can be translated to the SQL server?
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- System.NotSupportedException: Can only project the last entity type in the query being translated
- How to rewrite EF LINQ query that used to work in .NET Core 2.0 but doesn't in 3.0?
- Get next element from Query after element with specified Id. The LINQ expression could not be translated
- I have a LINQ statement that is partially query and partially method. How can I do this using one or the other?
- How can I simplify (speed up) the selecting query from a database that contains more than 1 million records using LINQ
- Can I allow queried objects to affect the query that fetches them with Linq and NHibernate?
- EF Core (LINQ) - The Query expression could not be Translated
- MVC Core and EF Core data grouping with Linq or something that can produce the desired result
- Can I return the 'id' field after a LINQ insert?
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- Why does a GC after a LINQ query free the WhereListIterator but not the Func representing the condition?
- How can I trace the query produced by the documentdb Linq provider?
- "Only arguments that can be evaluated on the client are supported for the String.Contains method"
- How can I get the first element after an element with LINQ-to-XML?
- How can you see the sql that is causing an error on SubmitChanges in LINQ to SQL?
- This foreach has a cast in the middle, can it be translated to linq?
- How can I view the Entity Framework LINQ query plan cache?
More Query from same tag
- Fast multiple string compare
- Is the IEnumerable.OrderBy().First() optimisation in .Net Core 3.1 documented anywhere?
- Casting a nullable in where clause in LinQ-to-entity without null-check
- Can I rewrite the following code using LINQ?
- Search In claims
- C# Linq Query with Multiple Joins with an await
- Entity Framework with an Intersect table and correspond Linq query
- DataTable to Xdocument Custom
- Malformed string exception Firebird + linq
- How to group by items that can grow?
- How to Union List<List<String>> in C#
- Exception when adding a toList() at the query? (C#)
- Comparing two collections
- handling a null in linq to sql query
- Why C# linq Distinct method is faster
- Linq query showing more data than the SQL alternative
- Unable to cast the type 'DynamicClass1' to type <T>. LINQ to Entities only supports casting EDM primitive or enumeration types
- How to query for 2 depths?
- Efficient Hierarchal Linq query using multiple properties
- Linq: Looking for an efficient way to search a column to see if it contains any word from a list of words
- LINQ: overriding a column data with another table's data using FK relationship
- Invalid column when i am not asking for the one
- Convert a DataTable to IList
- Why do I have to copy "this" when using LINQ in a struct (and is it OK if I do)?
- Why does a null string concatenated to a non null string evaluate to null?
- LINQ Expression Tree
- dynamic value in parent node in json from c# linq
- how to use LINQ to search for all user names that Starts With ("john")?
- What is Guid.NewGuid() doing in LINQ to Entities?
- How to query ASP.NET MVC 5 application for class-level attributes