Set operations: support when placed after client evaluation in projection

See original GitHub issue

Test case:

public virtual Task Client_eval_Union_FirstOrDefault(bool isAsync)
    => AssertFirstOrDefault<Customer>(
        isAsync, cs => cs
            .Select(c => ClientSideMethod(c))
            .Union(cs));

Can probably be punted post-3.0 (can be easily worked around).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:30 (12 by maintainers)

github_iconTop GitHub Comments

34reactions
Maleaumecommented, May 1, 2020

Your example is not complete because you request on same table I have the use case with two tables with one different column but i want to make a union in a common object. I Can’t I have the same error

[TableA]
class A {
    public string NameA;
    public string DescriptionA;
}

[TableB]
class B {
    public string NameB;
    public string DescriptionB;
}

class UnionClass
{
    public string Name;
    public string Description;
}

I would like to

var queryableA  = Context.A.select( x => new UnionClass{ Name =x.NameA,Description = x.DescriptionA);
var queryableB = Context.Bselect( x => new UnionClass{ Name =x.NameB,Description = x.DescriptionB);

var queryUnion = queryableA.Union(queryableB)
var result = queryUnion .Select( x=> x.Name.contains("RE));
9reactions
rojicommented, May 1, 2020

@Maleaume @brandonsmith86 @BeejeeDS the only issue here is with set operations after a client projection - as long as you write your query to place the union before that, there’s no issue. You can typically do this by projecting to an anonymous type (which works fine and doesn’t require client translation) and doing everything you need on that. If you need to project out to your own type, do that at the end.

For example:

var result = ctx.A
    .Select(a => new { Name = a.NameA, Description = a.DescriptionA })
    .Union(ctx.B
        .Select(b => new { Name = b.NameB, Description = b.DescriptionB }))
    .Where(x => x.Name.StartsWith("a"))
    // Add any further operations to be executed in the database here
    .Select(x => new UnionClass
    {
        Name = x.Name,
        Description = x.Description
    })
    .ToList();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't process set operations after client evaluation efcore
This is a limitation of EF Core and I don't think it will be resolved ever. First list is easily translatable to the...
Read more >
Can't process set operations after client evaluation
Unable to translate set operation after client projection has been applied. Consider moving the set operation before the last 'Select' call.
Read more >
Can't process set operations after client evaluation efcore ...
This is a limitation of EF Core and I don't think it will be resolved ever. First list is easily translatable to the...
Read more >
Client vs. Server Evaluation - EF Core
EF Core supports partial client evaluation in the top-level projection (essentially, the last call to Select() ).
Read more >
Tracking vs. No-Tracking Queries - EF Core
An individual query can be set to be no-tracking. ... If EF Core materializes an entity instance for client evaluation, it will be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found