locked
Returning an alternative if the currenct record doesn't exist RRS feed

  • Question

  • User1034446946 posted

    Hi

    Just looking for some info, I have my text stored in a table which has a culture code to reference

    so it would be something like

    _db.Text.Where(t => t.CultureCode = "en-gb" && t.SomeOtherField == 1).FirstOrDefault();

    now I can build another query that returns a more defauly setting

    _db.Text.Where(t => t.CultureCode.StartsWith("en") && t.SomeOtherField == 1).OrderBy(o => o.CulturePosition).FirstOrDefault();

    However my question is, is the only option to run two queries if the first doesn't have a record or is there a better way? I would hoping not to hit the database twice for each text field.

    Any suggestions would be appriciate.

    Tuesday, July 10, 2018 11:40 PM

Answers

All replies