What are the advantages of working with a fluent interface with LINQ?
I have this code:
Employees.cs
namespace LinqConsulta
{
class Empregados : List<Empregado>
{
public Empregados Lista()
{
this.Add(new Empregado(1, "Maria", "[email protected]", "11 1111 1111"));
this.Add(new Empregado(2, "João", "[email protected]", "22 2222 2222"));
this.Add(new Empregado(3, "José", "[email protected]", "33 3333 3333"));
return this;
}
}
}
Employee.cs
namespace LinqConsulta
{
class Empregado
{
public int Id { get; set; }
public string Nome { get; set; }
public string Email { get; set; }
public string Telefone { get; set; }
public Empregado() { }
public Empregado(int id, string nome, string email, string telefone)
{
this.Id = id;
this.Nome = nome;
this.Email = email;
this.Telefone = telefone;
}
}
}
Form1.cs
namespace LinqConsulta
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_load(object sender, EventsArgs e)
{
Empregados lista = new Empregados().Lista();
var consulta = from empregado in lista
orderby empregado.Nome
select empregado;
dataGridView1.DataSource = consulta.ToList();
}
}
}
I'm working with the query ( var consulta = from
) in SQL format and would like to know how to make this query leaner, with a fluent interface?