Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How can I perform a join operation between an in-memory list and a SQL database table using EFCore #33414

Closed
Esperadoce opened this issue Mar 27, 2024 · 2 comments

Comments

@Esperadoce
Copy link

Esperadoce commented Mar 27, 2024

I have the following code :

List<MyComplexObject> listInMemory = new List<MyComplexObject>
{
    new MyComplexObject { Id1 = 1, Id2 = 2, Name = "Name1" },
    new MyComplexObject { Id1 = 3, Id2 = 4, Name = "Name2" }
};

// And a DbSet in your DbContext
public DbSet<MyEntity> MyEntities { get; set; }


var result = MyEntities
    .Join(listInMemory, 
          entity => new { entity.Id1, entity.Id2 }, 
          complexObject => new { complexObject.Id1, complexObject.Id2 }, 
          (entity, complexObject) => entity);

I'm trying to verify a list of elements that exist in memory against something in my database, but I'm encountering this error.

resultSelector: (entity, complexObject) => entity)' could not be
translated

My problem would be simpler if I only have a list of in that case i could use something like this .Where(entity=>listOfIds.Contains(entity.Id)) unfortunately I have 2 "ids" that I need to check and I tried a list.Any but didn't work either

@roji
Copy link
Member

roji commented Mar 27, 2024

Since 8.0, EF supports joining on a primitive list (that is, a list of ints, strings...) - as well as any other LINQ operator - but it does not yet support lists of complex types. #31237 is the issue tracking that.

@roji
Copy link
Member

roji commented Mar 27, 2024

Duplicate of #31237

@roji roji marked this as a duplicate of #31237 Mar 27, 2024
@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2024
@roji roji self-assigned this Mar 27, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants