Table-Valued Function in Entity Framework 5.0 Entity Framework 5.0 supports Table-valued functions of SQL Server. Table-valued functions are similar to stored procedure with one key difference: the result of TVF is composable which means that it can…
以下系列文章为Entity Framework Turial Basics系列 http://www.entityframeworktutorial.net/EntityFramework5/entity-framework5-introduction.aspx ----------------------------------------------------------------------------------------------------------------------…
Setup Entity Framework Environment: Entity Framework 5.0 API was distributed in two places, in NuGet package and in .NET framework. The .NET framework 4.0/4.5 included EF core API, whereas EntityFramework.dll via NuGet package included EF 5.0 specifi…
Download Sample Project: Download sample project for basic Entity Framework tutorials. Sample project includes SchoolDB.mdf for SQL Server 2012. It also includes SchoolDB.sql script if you are using a different version of SQL Server.…
Colored Entity in Entity Framework 5.0 You can change the color of an entity in the designer so that it would be easy to see related groups of entities in the designer from Visual Studio 2012 onwards. To change the color of an entity, select entity i…
Multiple Diagrams in Entity Framework 5.0 Visual Studio 2012 provides a facility to split the design time visual representation of the Entity Data Model. This means that you can have multiple diagrams for one Entity Data Model. You can create a new d…
Lazy Loading: One of the important functions of Entity Framework is lazy loading. Lazy loading means delaying the loading of related data, until you specifically request for it. For example, Student class contains StudentAddress as a complex property…
Eager Loading: Eager loading is the process whereby a query for one type of entity also loads related entities as part of the query. Eager loading is achieved using the Include() method. In the following example, it gets all the students from the dat…
Spatial Data type support in Entity Framework 5.0 MS SQL Server 2008 introduced two spatial data types, geography and geometry. Geography represents data in a round-earth coordinate system and geometry represent data in a Euclidean (flat) coordinate…
Enum in Entity Framework: You can now have an Enum in Entity Framework 5.0 onwards. EF 5 should target .NET framework 4.5 in order to use Enum. Enum can be created for the following data types: Int16 Int32 Int64 Byte SByte You can create and use an E…
Migration from Entity Framework 4.1/4.3 to Entity Framework 5.0/6.0 To migrate your existing Entity Framework 4.x project to Entity Framework 5.0 using VS2012, first target .NET Framework 4.5: Second, remove the existing Entity Framework 4.1/4.3 refe…
Stored Procedure in Entity Framework: Entity Framework has the ability to automatically build native commands for the database based on your LINQ to Entities or Entity SQL queries, as well as, build the commands for inserting, updating, or deleting d…
Concurrency in Entity Framework: Entity Framework supports Optimistic Concurrency by default. In the optimistic concurrency, EF saves the entity to the database, assuming that the same data has not changed since the entity was loaded. If it determine…
Update Entity Graph using DbContext: Updating an entity graph in disconnected scenario is a complex task. It is easy to add a new entity graph in disconnected mode, but to update an entity graph needs careful design consideration. The problem in upda…
Disconnected Entities: Before we see how to perform CRUD operation on disconnected entity graph, let's see how to associate disconnected entity graph with the new context instance. There are two things we need to do when we get a disconnected entity…
Persistence in Entity Framework There are two scenarios when persisting an entity using EntityFramework, connected and disconnected scenarios. Connected Scenario: This is when an entity is retrieved from the database and persist is used in the same c…
Change Tracking in Entity Framework: Here, you will learn how entity framework tracks changes on entities during its life time. Entity framework supports automatic change tracking of the loaded entities during the life time of the context. DbChangeTr…
Querying with EDM: We have created EDM, DbContext, and entity classes in the previous sections. Here, you will learn the different types of queries an entity framework supports, which is in turn converted into SQL query for the underlaying database.…
Choose development approach with Entity Framework: We have seen Code-first, Model-first and Database-first approaches in the previous sections. So, now you have to make a decision about which development approach to use in your application. The follo…
Database First development with Entity Framework: We have seen this approach in Create Entity Data Model where we created the EDM, context and entity classes from an existing database. So, when you generate EDMX from an existing database then it is a…
Model First development with Entity Framework: In the Model First approach, you create Entities, relationships, and inheritance hierarchies directly on the design surface of EDMX and then generate database from your model. So, in the Model First appr…
Code First development with Entity Framework: Entity Framework supports three different development approaches to use entity framework in your application. Code First Model First Database first Code First: In the Code First approach, you avoid workin…
Types of Entity in Entity Framework: We created EDM for existing database in the previous section. As you have learned in the previous section that EDM contains entities for each table in the database. There are two types of Entities in Entity Framew…
DBContext: As you have seen in the previous Create Entity Data Model section, EDM generates the SchoolDBEntities class, which was derived from the System.Data.Entity.DbContext class, as shown below. The class that derives DbContext is called context…
Model Browser: We have created our first Entity Data Model for School database in the previous section. The visual designer of EDM does not display all the objects it creats. It only display entities which are mapped to the database tables and views.…
Create Entity Data Model: Here, we are going to create an Entity Data Model (EDM) for SchoolDB database and understand the basic building blocks. Entity Data Model is a model that describes entities and the relationships between them. Let's create fi…
Entity Framework Architecture The following figure shows the overall architecture of the Entity Framework. Let us now look at the components of the architecture individually: EDM (Entity Data Model): EDM consists of three main parts - Conceptual mode…
What is Entity Framework? Writing and managing ADO.Net code for data access is a tedious and monotonous job. Microsoft has provided an O/RM framework called "Entity Framework" to automate database related activities for your application. Microso…
Validate Entity You can write custom server side validation for any entity. To accomplish this, override ValidateEntity method of DBContext as shown below. protected override System.Data.Entity.Validation.DbEntityValidationResult ValidateEntity(DbEnt…
Execute Native SQL Query You can execute native raw SQL query against the database using DBContext. You can execute the following types of queries: SQL query for entity types which returns particular types of entities SQL query for non-entity types w…