Search code examples
mysqllinq-to-sqlbltoolkit

How to get list of object by list of ids with BLToolkit?


I'm trying to write a code that will be translated into the following query:

SELECT * FROM players WHERE Id IN (xxx)

With MS-SQL and linq2sql I used "Contains" construction and that worked well.

Now (for MySQl and BLToolkit) I did it this way:

    public static IList<Player> GetPlayersByIds(IList<int> ids, DbManager db)
    {
        return db.GetTable<Player>().Where(pl => ids.Contains(pl.Id)).ToList();
    }

but the execution of this code returns the following error:

value(vfm_elita.elita_table.player.Player+<>c__DisplayClass13).ids.Contains(pl.Id)' cannot be converted to SQL.

Is there any solution for this?

If no, how can I query a list of objects by the list of IDs?

Thank you very much, any feedback is welcome.


Solution

  • It looks like I had aged version of BLToolkit that has a bug. After getting 4.1 (that has fully rewritten linq2sql converter) problem was resolved.