I wrote this piece of code to search for "Vendor" (Salesman), which satisfies the condition for the same "codigo" (id) entered by the TextBox user:
using (TccContext context = new TccContext()) { Vendedor[] query = (from vendedor in context.Vendedores where vendedor.codigo == Convert.ToInt64(this.textBoxProcurarCodFuncionario.Text) select vendedor).ToArray(); if (query.Length == 1) { textBoxCodigo.Text = query[0].codigo.ToString(); textBoxNome.Text = query[0].nome; textBoxTotalVendaMensal.Text = query[0].totalVendaMensal.ToString(); } else { MessageBox.Show("Código não encontrado,\n tente novamente...", "Atualizar Funcionário", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Limpar(); } }
I would like to replace the ToArray method for SingleOrDefault, but I'm stuck in:
Returns a single element of a sequence or the default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.
In this case, what will be the “default” as indicated in the documentation, I would like to be able to handle this “exception”, but I don’t know what it is?
Can someone explain to me what will be the "default"? I just started using Entity Framework, so not too much with me.
Thanks in advance.
Zignd source share