Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

You can also use Contains in BLToolkit, check the file ..\UnitTests\Linq\Functions.cs in the BLToolkit sources for some unit-tests using contains

I think (without testing) that the problem with you current code is the use of IList just try it with a List

public static IList<Player> GetPlayersByIds(List<int> ids, DbManager db)
{
    return db.GetTable<Player>().Where(pl => ids.Contains(pl.Id)).ToList();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top