locked
select specific records without knowing a selector RRS feed

  • Question

  • User1034446946 posted

    Hi

    I have a model something like

    model
    {
    public int id {get;set;} public int selector [get;set;} public string Somefield {get;set;}
    public bool status {get;set;} } new model {id = 1, selector = 1, Somefield = "a", status = false} new model {id = 2, selector = 2, Somefield = "b", status = false} new model {id = 3, selector = 1, Somefield = "c", status = false} new model {id = 4, selector = 3, Somefield = "a", status = false} new model {id = 5, selector = 4, Somefield = "a", status = false} new model {id = 6, selector = 7, Somefield = "a", status = false} new model {id = 7, selector = 2, Somefield = "d", status = false}
    new model {id = 8, selector = 1, Somefield = "a", status = false}

    now I want do a search for Somefield = "a", which is easy enough, this would return 4 records, however I only want to return one set of selectors without knowing the selector value at the time of search.

    So my brain is thinking order by selector, grab first selector, but I don't know how to grab the first selector only.

    Ay suggestions would be appriciated.

    Monday, February 19, 2018 11:37 AM

Answers

  • User475983607 posted

    This has to be something missing from this post but simply return FirstOrDefault().

    So my brain is thinking order by selector, grab first selector, but I don't know how to grab the first selector only.

    There is no concept of order in set theory.  Order is a GUI thing.  As such only you know what "first" means.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 19, 2018 3:07 PM
  • User283571144 posted

    Hi  enendaveyboy,

    Thanks for the info, i think i am just going to have to run two queries which isn't a massive problem I just wanted to find out if there was another way.

    In my opinion. there are no way to achieve your requirement.

    If you don't know the the selector, you could directly use the firstordefault to get the result. In my opinion this is two queries.

    If you wants to the selector order by the number, you could firstly select the result according to "Somefield " and order by the "selector".

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 23, 2018 7:48 AM

All replies

  • User475983607 posted

    This has to be something missing from this post but simply return FirstOrDefault().

    So my brain is thinking order by selector, grab first selector, but I don't know how to grab the first selector only.

    There is no concept of order in set theory.  Order is a GUI thing.  As such only you know what "first" means.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 19, 2018 3:07 PM
  • User1034446946 posted

    Thanks for the info, i think i am just going to have to run two queries which isn't a massive problem I just wanted to find out if there was another way.

    Monday, February 19, 2018 3:11 PM
  • User283571144 posted

    Hi  enendaveyboy,

    Thanks for the info, i think i am just going to have to run two queries which isn't a massive problem I just wanted to find out if there was another way.

    In my opinion. there are no way to achieve your requirement.

    If you don't know the the selector, you could directly use the firstordefault to get the result. In my opinion this is two queries.

    If you wants to the selector order by the number, you could firstly select the result according to "Somefield " and order by the "selector".

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 23, 2018 7:48 AM