|Microsoft ADO.NET Entity Framework Step by Step|
Author: John Paul Mueller
Entity Framework (EF) is designed to make it easy to create ADO.NET apps that access data with minimal coding. It’s a great idea, but as with so many Microsoft products, it’s tricky to know what the ‘best’ way of achieving your aim is. In this book John Paul Mueller works through 44 examples showing different aspects of Entity Framework. The book assumes you know C# and ADO.NET, and you’re probably better off if you also have a basic grasp of T-SQL.
The book concentrates heavily on a combination of Windows Forms and the Model First modeling method, with only brief mentions of the alternative Database First and Code First options. If you’re not familiar with Entity Framework, what you need to know is that you have a choice of three ways to model your data. If you’ve got an existing database that you’re wanting to work with, then you would usually generate the ADO.NET Entity Data Model from the database – Database First. If you want to start from Entity Framework and create the model there, you choose Model First, create the entities, relationships and inheritance hierarchies within Entity Framework, then get EF to generate the Data Definition Language (DDL) to execute in your database server to create the database. The third option is to use Code First. As the name suggests, you write code to create POCO (Plain Old CLR Object) classes, and create the database from those.
Mueller assumes you’ll be using Model First. So far as I can tell, this is because if you’re using Database First, the model will be created for you so you won’t need the design facilities of EF; if you’re using Code First, you again won’t be using the model design facilities EF provides. It would have been nice to have had a few more examples of how each of these alternatives is used, but I can sort of understand the decision to concentrate on Model First.
The decision to concentrate so much on Windows Forms is less easy to justify. There are plenty of alternatives to Windows Forms – Web Forms, MVC, WCF – but Mueller stays firmly with Windows Forms. If you want to learn how to use EF with other platforms, you’ll need to read more once you’ve finished the book.
The material that is covered is well written and does take you through the majority of EF features, including those in EF 5. Part I of the book introduces EF, works through a simple example, and shows how to create simple queries and workflows. The next two chapters cover ‘basic tasks’; generating and using entity objects, creating queries using objects, modifying data, viewing data, and creating a master detail form.
Part II looks at how to perform basic Create, Review, Update and Delete (CRUD) operations and then Part III explores the different options for manipulating data – LINQ, Entity SQL, stored procedures, views, and Table-Valued Functions. Although SQL Server has supported TDFs since SQL 2005, they were new in EF 5. If you’ve not encountered them, they’re essentially user defined functions that return a table. Taking the overall coverage of the options for manipulating data, while the author does a good job of showing the different uses, particularly of LINQ and Entity SQL, he sticks to fairly simple examples and I’d have preferred a few more advanced examples.
Part IV of the book covers entity errors and how to work around them, with good chapters on dealing with exceptions, concurrency problems, and performance problems. Obviously you won’t find the exact answer to your particular problem, but at least there are hints on where to look.
The book ends with a section on advanced management techniques. There’s a chapter on creating custom entities that shows how to set up POCO classes, followed by a chapter showing how to map data types to properties once you’ve created your classes. The book ends with some coverage of more advanced topics such as an introduction to how to develop multiple diagrams for a model, mapping a stored procedure that returns multiple result sets, and creating entities with inheritance. If you have dabbled with EF before, this will be the most interesting part of the book.
Overall, this is a good introduction to EF, particularly if you’re happy working with Model First and Windows Forms. It has its limitations, but succeeds in getting the main story of EF straight.
|Last Updated ( Wednesday, 23 July 2014 )|