How do I use the SQL WHERE IN construct with PetaPoco?

前端 未结 5 1164
鱼传尺愫
鱼传尺愫 2020-12-24 13:20

I have a database table named Tags (Id, Name) from which I would like to select the ones where the name matches a name in a list. In SQL I would use something like:

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-24 13:35

    Maybe, it's not a good way setting too many params in sql, the max params limit is 2100.

    @Murat

    string[] array = new string[] {"Name1","Name2" };
    var foo = BasicRepository.Fetch("WHERE PersonnelId IN > (@0)", array.ToArray());
    

    Constructing stander SQL in string, and check the LAST excute-sql, alway match your need.

    var userIDs = from user in UserList select user.UserID;
    db.Delete("where UserID in (" + string.Join(",", userIDs) + ")");
    

提交回复
热议问题