Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Returning an alternative if the currenct record doesn't exist

$
0
0

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.


Viewing all articles
Browse latest Browse all 1698

Trending Articles