Pomelo.EntityFrameworkCore.MySql
Pomelo.EntityFrameworkCore.MySql copied to clipboard
how to make a contains query of composite key
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?
Row Constructor isn't supported in EF Core, see Expand tuples to multiple columns for more details.
@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();
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.
@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.