Finding out if a list of Objects contains something with a specified field value?

前端 未结 6 2078
遥遥无期
遥遥无期 2020-12-03 10:20

I have a list of DTO received from a DB, and they have an ID. I want to ensure that my list contains an object with a specified ID. Apparently creating an object with expect

6条回答
  •  温柔的废话
    2020-12-03 10:34

    You requirement is not clear to me. When you say 'ensure that my list contains an object with a specified ID' do you want to:

    1. detect if the ID is present and act accordingly
    2. always include the DTO with the required ID in your results

    Most responses have assumed you mean 1, however when thinking about it you could just as well mean 2 given the wording of the question. You could include the required result by altering your query:

    SELECT * FROM employee WHERE firstname = 'John' OR id = 42;
    

提交回复
热议问题