As I mentioned in the comments, either a
while[
^] or a
do..while[
^] will do the trick.
string code;
using (var db = new Database())
{
do
{
code = Code();
}
while (db.Codes.Any(pc => pc.Code == code))
}
string code = Code();
using (var db = new Database())
{
while (db.Codes.Any(pc => pc.Code == code))
{
code = Code();
}
}