Entity Framework allows you to provide a strongly typed object framework (ORM) over your database. This helps abstract the database away allowing it to be replaced with other technologies as needed.
using (SqlConnection conn = new SqlConnection()){conn.ConnectionString = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=True";conn.Open();SqlCommand cmd = conn.CreateCommand();cmd.CommandText = "SELECT * FROM Customers WHERE CompanyName LIKE '" + companyNameTextbox.Text + "%'";bindingSource1.DataSource = cmd.ExecuteReader();}
❌ Figure: Bad example - using ADO.NET and not strongly typed
var results = dbContext.Customers.Where(c => c.CompanyName.StartsWith(companyNameTextbox.Text));customersBindingSource.DataSource = results;// Or evenvar results = dbContext.Customers.Where(c => c.CompanyName.StartsWith(companyNameTextbox.Text)).Select(c => new{c.CompanyName,c.Phone});customersBindingSource.DataSource = results;
✅ Figure: Good example - at least 4 good reasons below
OrderBy, GroupBy, FirstOrDefault, Count, Any and many more