PomeloFoundation / Pomelo.EntityFrameworkCore.MySql

Entity Framework Core provider for MySQL and MariaDB built on top of MySqlConnector
MIT License
2.68k stars 382 forks source link

how to make a contains query of composite key #1635

Open hoxcape opened 2 years ago

hoxcape commented 2 years ago

The issue

In mysql,I can make a query like:

select * from `Table` where (Id,Name) in ((1,"test"),...);

How can I make a query like above in ef core using pomelo driver?

mguinness commented 2 years ago

Row Constructor isn't supported in EF Core, see Expand tuples to multiple columns for more details.

hoxcape commented 2 years ago

@mguinness how about this syntax?translate Contains method of object array

var entities= ctx.Entities.Where(e => new[]
{
    new { Id = 1, Type = 1 },
    new { Id = 2, Type = 1 }
}.Contains(new { b.Id, b.Type})).ToList();
mguinness commented 2 years ago

That is the syntax that is being proposed, but it is still in planning stage. See similar issue https://github.com/npgsql/efcore.pg/issues/898 for PostgreSQL.

lauxjpn commented 2 years ago

@hoxcape You should be able to build something semantically equivalent by manually crafting the expression tree of the conditions that you want and use it as the Where() parameter.

If you need some sample code, let me know.