Wednesday 8 January 2014

Entity Framework 5 new features

Some of the important features of Entity Framework 5.0 

Introduction:

EF 5.0 can be used in Visual Studio 2010 and Visual Studio 2012. It is used with .NET 4.0 and .NET 4.5. With .NET 4.5, this release introduces some new features 
                     
§  Enum support:
§  Spatial Data Types 
§  Performance Enhancement
Ø  Repeat Execution Time
Ø  automatic compilation
Ø  End to end performance
§  CF will detect if you have localDB available for creating new database
§  CF will add tables to existing db
§  Table Valued functions


Enum Support:

 Entity framework 5 provides support for Enum datatype. Now a property or field in a class can be declared as a Enum Type. Entity framework will successfully save the entity in DB and will display it back. But it will not store Enum type as static data in table rather will store the enum type as int value type.
e.g.
Public  enum  Color {
White,
Black,
Red,
Yellow
}

Public  Class Car
{
                Public  Color BodyColor{get;set;}
                Public  decimal Price {get;set;} 
               Public string BrandName {get;set;}
}









If we create an instance of Car and save into the database table.

    Car mycar = new Car();
mycar. BodyColor = Color.Red;
mycar.Price = 800000.00;
mycar.BrandName = “DZX”;

Table will have the data BodyColor as 2. (base value). There will not be any static table with records as White, Black, Red and Yellow.

Spatial Data type:

Entity framework 5.0 is now equipped with DbGeometry datatype which is equivalent to Geometry datatype in SQLServer.
Now we can use DbGeometry datatype for location / Geographical coordinate storing and manipulation.
e.g.
                Public class Office {
                               Public string Name{get;set;}
                              Public DbGeometry Location{get;set;}
             }
            Office Myoffice = new Office();
            Myoffice.Name = “XYZ”;
           Myoffice.Location = DbGeometry.FromText("POINT(40.644047 -73.782291)");

 The same will get persist into the database table as Geometry datatype in SQLServer.
            
               

No comments:

Post a Comment