Entity Framework Integration

What is Entity Framework?

Entity Framework (EF) is an object-relational mapper (ORM) that eliminates the need for most data-access code that developers usually need to write. It ships with .NET 4.0 and later and is Microsoft’s preferred data access strategy for most applications.

With EF you create a .NET object model that reflects how your database tables should be accessed within your application. Entity Framework automatically generates the data access code to go to and from your database so you don’t have to write either T-SQL code or laborious column-by-column parameter or data mappings.

EF Makes Data Access Easy

Entity Framework can automatically generate all of the basic insert, update, and delete actions for your application but the real power is the ability to use LINQ to create complex queries, with full intellisense support, right in Visual Studio.

using (var model = new Entities())
{
	var employeeQuery = model.Employee.Where(e => e.LastName == null);
	foreach (var emp in employeeQuery)
	{
		Console.WriteLine(emp.EmployeeID + " " + emp.FirstName);
	}				
}

EF supports more interesting scenarios as well - such as filtering by data in a relationship and sorting.

using (var model = new Entities())
{
    return ctx.Set<SessionCategorization>()
        .Where(s => s.IsSuppressed == false)
        .Where(s => s.LogEvents.Any(le => le.SessionEventId == sessionEventId))
        .OrderByDescending(s => s.StartedOn)
        .ToList();
}

Use VistaDB with EF for Rapid Application Development

VistaDB comes with providers for EF 4-6. You can design your database using VistaDB’s tools and then automatically generate or update an entity model within your application. Using the EF EDMX designer you can clean up property and relationship names, map stored procedures and views, and tune the entity model.

Entity Framework Diagram

At runtime EF will work with the VistaDB provider to create T-SQL optimized for VistaDB and run it.

Going Deeper

To get started, see Using VistaDB with Entity Framework

The No Hassle Embedded Database for .NET

License your team and deploy worldwide, royalty-free, starting at $1,595/site