Introducing Entity Framework

So what is Entity Framework (EF)? Is it some other fancy framework that I need to learn? If these thoughts are coming to mind, get rid of them, as EF is just a set of .NET APIs for accessing data. EF is the official data access tool from Microsoft. Like most Microsoft products, it originated from Microsoft Research, and later it was adopted by the ADO.NET team as the next innovation in Microsoft's data access technology. EF has evolved over time. It had a sluggish start in 2008 when developers found it hard to digest a new way of accessing data. But with EF4 (yes, the second version of EF was 4, as it was aligned with .NET 4), it had become the norm to use EF for data accessing with .NET. Continuing the journey, it became open source in version EF6 and moved to CodePlex (http://www.codeplex.com). This opened up new avenues for EF. As it became open source, the community could make contributions as well. Now that CodePlex is archived, EF6 has moved to GitHub and is actively being developed.

EF is also referred to as an ORM. What is an ORM? An ORM stands for object-relational mapping, which broadly means mapping objects to relational tables. An ORM refers to the technique for converting data between two incompatible type systems. For example, let us consider a C# plain old CLR object (POCO) of a Person class. An instance of the Person class has the Name, Id, and Age properties of string, int and int types, respectively. In the SQL database, this data would be persisted in a table named Person with the columns Name, Id, Age, and so on. An ORM maps the Person POCO to the Person database table. The primary intent of an ORM is to try and shield the developer from having to write optimized SQL code for this inter-conversion. An ORMs are designed to reduce the friction between how data is structured in a relational database and how the classes are defined. Without an ORM, we typically need to write a lot of code to transform database results into instances of the classes. An ORM allows us to express our queries using our classes, and then an ORM builds and executes the relevant SQL for us, as well as materializing objects from the data that came back from the database. What I say here is an oversimplification and there's a lot more to an ORMs and to Entity Framework than this. Entity Framework can really enhance developer productivity and we will see this while developing the movie booking app. EF has a dedicated team at Microsoft. It has been around for almost a decade now. Rather than writing the relevant SQL to target whatever relational database you're working with, Entity Framework uses the Language-Integrated Query (LINQ) syntax that's part of the .NET framework. LINQ to Entities allows developers to use a consistent and strongly-typed query language irrespective of what database they're targeting. Additionally, LINQ to Objects is used for querying other elements of .NET, even InMemory objects, so developers benefit from their knowledge of LINQ.

Since we are working with .NET Core and want to make a cross-platform app, we cannot use Entity Framework, as it's not compatible with ASP.NET Core. Don't worry! We have solutions. Either we can compile our project against the full .NET Framework or we can use the latest and greatest version of Entity Framework called Entity Framework Core, which is a lightweight and cross-platform version of Entity Framework, rewritten from scratch to support a variety of platforms. Let's discuss Entity Framework Core.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.72.224