Click here to monitor SSC
  • Av rating:
  • Total votes: 113
  • Total comments: 13
Amirthalingam Prasanna

Entity Framework: The Cribsheet

26 May 2008

Entity Framework- The Crib Sheet

For things you need to know rather than the things you want to know


Prasanna Amirthalingam provides an overview of Entity Framework and how it can be used. He shows that it can provide an excellent interface between the Object-oriented model and the relational. The Entity Framework allows developers to work with data in the form of objects and properties without having to concern themselves directly with either the stored procedures or functions of the defined interface, or the underlying database tables and columns where this data is stored.

Contents

Introduction

Database developers and application developers need to model business processes and data differently. Database developers use a relational model to represent data and develop stored procedures to represent processes. Application developers use the richness of object oriented models to work with business data and business processes. This mismatch between the relational world and the object oriented world can be addressed by using the ADO.NET Entity Framework. This article is based on the ADO.NET Entity Framework that ships with Visual Studio.NET 2008 Service Pack 1 Beta.

The ADO.NET entity framework is an evolution of ADO.NET to provide object relational mapping between conceptual entities and the data store. Conceptual entities are standard .NET classes. The ADO.NET entity framework provides a mapping technology to map these conceptual entities to the data store schema of your database. This allows an application developer to work with the conceptual entities without having to be concerned  about the underlying data model.

ADO.NET Entity Data Model

The ADO.NET entity framework uses an Entity Data Model. The Entity Data Model consists of the storage schema, the conceptual schema, the mapping schema and the entity classes.

Storage Schema Definition (SSDL)

The storage schema describes, in an XML definition, the schema of the data store. This is the exact schema of your data store. The storage schema definition can be generated directly from the data store. The Storage schema describes the schema of a database table as an entity type. The following XML fragment shows the definition for a Customer table:

<EntityType Name="Customer">

  <Key>

    <PropertyRef Name="ID" />

  </Key>

  <Property Name="ID" Type="int" Nullable="false" />

  <Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="25" />

  <Property Name="City" Type="nvarchar" MaxLength="25" />

  <Property Name="Country" Type="nvarchar" Nullable="false" MaxLength="25" />

  <Property Name="IsCorporate" Type="bit" Nullable="false" />

  <Property Name="CompanyName" Type="nvarchar" MaxLength="25" />

  <Property Name="Designation" Type="nvarchar" MaxLength="25" />

  <Property Name="LastModified" Type="timestamp" StoreGeneratedPattern="Computed" />

</EntityType>

The storage schema also describes relationships between tables as an association. The following definition for an association shows that the Customer table has a relationship with an Order table:

<Association Name="FK_Orders_Customers">

  <End Role="Customer" Type="ContosoModel.Store.Customer" Multiplicity="1" />

  <End Role="Order" Type="ContosoModel.Store.Order" Multiplicity="*" />

<ReferentialConstraint>

    <Principal Role="Customer">

      <PropertyRef Name="ID" />

    </Principal>

    <Dependent Role="Order">

      <PropertyRef Name="CustomerID" />

    </Dependent>

  </ReferentialConstraint>

</Association>

 

The storage schema also refers to any stored procedures in the data store. The following XML definition defines an existing stored procedure named SelectByCountry that accepts a single parameter named ctry:

<Function Name="SelectByCountry" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo">

  <Parameter Name="ctry" Type="varchar" Mode="In" />

</Function>

 

Finally all the defined entity types and associations are mapped into an entity container. The entity types are grouped into an entity set and the associations are grouped into an association set.

<EntityContainer Name="dbo">

  <EntitySet Name="Customer" EntityType="ContosoModel.Store.Customer" store:Type="Tables" />

  <EntitySet Name="Order" EntityType="ContosoModel.Store.Order" store:Type="Tables" />

  <AssociationSet Name="FK_Orders_Customers" Association="ContosoModel.Store.FK_Orders_Customers">

    <End Role="Customer" EntitySet="Customer" />

    <End Role="Order" EntitySet="Order" />

  </AssociationSet>

</EntityContainer>

Conceptual Schema Definition (CSDL)

The conceptual schema describes the conceptual entities as entity types and is defined in XML. This is created to describe the schema of the conceptual entities. Conceptual entity types are .NET classes. Though this schema can be auto-generated, most of the times the application developer would alter the conceptual schema to reflect the model used for the conceptual entities. If the conceptual schema is auto-generated it would simply map a conceptual entity type to a table. The following shows the schema for two conceptual entities named Customer and CorporateCustomer. The CorporateCustomer entity type inherits from the Customer entity type.

<EntityType Name="Customer">

  <Key>

    <PropertyRef Name="ID" />

  </Key>

  <Property Name="ID" Type="Int32" Nullable="false" />

  <Property Name="Name" Type="String" Nullable="false" MaxLength="25" Unicode="true" FixedLength="false" />

  <Property Name="City" Type="String" MaxLength="25" Unicode="true" FixedLength="false" ConcurrencyMode="None" />

  <Property Name="Country" Type="String" Nullable="false" MaxLength="25" Unicode="true" FixedLength="false" />

  <Property Name="LastModified" Type="Binary" MaxLength="8" FixedLength="true" ConcurrencyMode="None" />

  <NavigationProperty Name="Order" Relationship="ContosoModel.FK_Orders_Customers" FromRole="Customer" ToRole="Order" />

</EntityType>

 

<EntityType Name="CorporateCustomer" BaseType="ContosoModel.Customer" >

  <Property Name="Designation" Type="String" Nullable="true" />

  <Property Name="CompanyName" Type="String" Nullable="true" />

</EntityType>

The conceptual schema also describes relationships between entity types as associations. These relationships are references in the conceptual schema for the entity type when an entity contains instances of another entity. For example in the schema above the navigation property in the Customer entity type references entities by using an association. The following schema shows the association between the Customer entity type and the Order entity type:

<Association Name="FK_Orders_Customers">

  <End Role="Customer" Type="ContosoModel.Customer" Multiplicity="1" />

  <End Role="Order" Type="ContosoModel.Order" Multiplicity="*" />

</Association>

Finally all the defined conceptual entity types are grouped into entity sets and associations are grouped into association sets. An entity container is defined to include the entity sets, association sets and any function definitions that can be mapped to stored procedures:

<EntityContainer Name="ContosoEntities">

  <EntitySet Name="Customer" EntityType="ContosoModel.Customer" />

  <EntitySet Name="Order" EntityType="ContosoModel.Order" />

  <AssociationSet Name="FK_Orders_Customers" Association="ContosoModel.FK_Orders_Customers">

    <End Role="Customer" EntitySet="Customer" />

    <End Role="Order" EntitySet="Order" />

  </AssociationSet>

  <FunctionImport Name="SelectByCountry" EntitySet="Customer" ReturnType="Collection(Self.Customer)">

    <Parameter Name="ctry" Mode="In" Type="String" />

  </FunctionImport>

</EntityContainer>

Mapping Schema (MSL)

The mapping schema definition is the glue that binds the conceptual model and the data store model. This XML definition contains information on how the conceptual entities, functions and associations are mapped to the storage schema. The following shows the mapping definition to map the Customer and CorporateCustomer conceptual entities defined in the conceptual schema to the database table named Customer defined in the storage schema:

<EntitySetMapping Name="Customer">

  <EntityTypeMapping TypeName="ContosoModel.Customer">

    <MappingFragment StoreEntitySet="Customer">

      <ScalarProperty Name="ID" ColumnName="ID" />

      <ScalarProperty Name="Name" ColumnName="Name" />

      <ScalarProperty Name="City" ColumnName="City" />

      <ScalarProperty Name="Country" ColumnName="Country" />

      <ScalarProperty Name="LastModified" ColumnName="LastModified" />

      <Condition ColumnName="IsCorporate" Value="0" />

    </MappingFragment>

  </EntityTypeMapping>

  <EntityTypeMapping TypeName="IsTypeOf(ContosoModel.CorporateCustomer)">

    <MappingFragment StoreEntitySet="Customer">

      <ScalarProperty Name="ID" ColumnName="ID" />

      <ScalarProperty Name="LastModified" ColumnName="LastModified" />

      <ScalarProperty Name="CompanyName" ColumnName="CompanyName" />

      <ScalarProperty Name="Designation" ColumnName="Designation" />

      <ScalarProperty Name="Country" ColumnName="Country" />

      <ScalarProperty Name="City" ColumnName="City" />

      <ScalarProperty Name="Name" ColumnName="Name" />

      <Condition ColumnName="IsCorporate" Value="1" />

    </MappingFragment>

  </EntityTypeMapping>

</EntitySetMapping>

The associations we define in the conceptual schema is mapped to the associations that we define in the storage schema

<AssociationSetMapping Name="FK_Orders_Customers" TypeName="ContosoModel.FK_Orders_Customers" StoreEntitySet="Order">

  <EndProperty Name="Customer">

    <ScalarProperty Name="ID" ColumnName="CustomerID" />

  </EndProperty>

  <EndProperty Name="Order">

    <ScalarProperty Name="ID" ColumnName="ID" />

  </EndProperty>

</AssociationSetMapping>

The functions we defined in the conceptual schema is mapped to the stored procedures defined in the storage schema

<FunctionImportMapping FunctionImportName="SelectByCountry" FunctionName="ContosoModel.Store.SelectByCountry" />

Entity Classes

Entity classes are .NET classes that are generated from the conceptual schema XML definition. The Entity classes are similar to business entities and will be used by the other layers in your application. When working with the Entity Data Model, any changes to the conceptual schema updates the auto generated .NET class definitions. Since these entity classes are partial classes you can extend the functionality by creating your own business logic for the entity classes. The generated entity classes also contain partial methods to plug in your own validation logic.

The following code shows the auto-generated class for the CorporateCustomer entity

C# Code:

[global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName = "ContosoModel", Name="CorporateCustomer")]

[global::System.Runtime.Serialization.DataContractAttribute(IsReference=true)]

[global::System.Serializable()]

public partial class CorporateCustomer : Customer

{

    public static CorporateCustomer CreateCorporateCustomer(int ID, string name, string country)

    {

        CorporateCustomer CorporateCustomer = new CorporateCustomer();

        CorporateCustomer.ID = ID;

        CorporateCustomer.Name = name;

        CorporateCustomer.Country = country;

        return CorporateCustomer;

    }

 [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute()]

    [global::System.Runtime.Serialization.DataMemberAttribute()]

    public string Designation

    {

        get

        {

            return this._Designation;

        }

        set

        {

            this.OnDesignationChanging(value);

            this.ReportPropertyChanging("Designation");

            this._Designation = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value, true);

            this.ReportPropertyChanged("Designation");

            this.OnDesignationChanged();

        }

    }

    private string _Designation;

    partial void OnDesignationChanging(string value);

    partial void OnDesignationChanged();

    //Other property definitions omitted

}

You can plug in your own validation logic by providing implementation for the partial methods. For each property in the entity class there will be partial methods that are called before a property changes and after the property is changed. For example on the above code let us assume we want to execute validation logic to make some validation checks if the designation is set to “Manager”. Then we can create a partial class definition for the above class and provide implementation for the OnDesignationChanging partial method as follows:

C# Code:

partial class CorporateCustomer

{

    partial void OnDesignationChanging(string value)

    {

        if (value.Equals("Manager"))

        {

            //validation checks

        }

    }

}

Working with the designer and tools

Visual Studio.NET 2008

Visual Studio has a project item template for an Entity Data Model. Adding an Entity Data Model to your project allows you to design the conceptual entities and map them to the data store using the Entity Framework designer. You can also create new conceptual entities, create association, and inherit from existing conceptual entities in the designer.

When you work with conceptual entities in the Entity Framework Designer, you can use the Mapping Details window to map the conceptual entity to a data store.

The Mapping Details window also has an alternate view to map your own user defined stored procedures to perform Inserts, Updates and Deletes for your conceptual entity

Visual Studio also has a Model Browser window that shows the conceptual entity types, entity sets and data store. This is similar to the Class Browser window and provides a better view to browse through the Entity Data model.

EdmGen tool

The EdmGen is a command line tool available with Visual Studio.NET 2008. You can use this to generate ADO.NET entity data model schema files and .NET classes for your application. For example the following command generates the XML files for the conceptual schema, storage schema, mapping schema and entity classes by using the database Contoso:

EdmGen /mode:FullGeneration /project:Contoso /provider:System.Data.SqlClient
/connectionstring:"server=.\sqlexpress;integrated security=true;database=Contoso"

You can change the mode for EdmGen to specify different starting points. For example if you have already created the storage schema, mapping schema and conceptual schema, and you want to generate the entity classes, you can change the mode to “EntityClassGeneration”. EdmGen is very useful when you want to configure it to be used along with an automated build process.

Working with data

Using Object Services

Object Services allows you to work with data as conceptual entities (.NET objects). This also allows you to perform CRUD operations on objects without writing query statements that are provider dependent or targeting a particular database product. The CRUD operations for entities are executed through the ObjectContext class. The ObjectContext class also manages state for retrieved entities.

Querying data

You have different ways of querying data through Object Services. When data is queried through Object Services, the results are returned as strongly typed objects. This allows you to work with data as working with any strongly typed object or collection in .NET. The simplest way to query data is by using the ObjectQuery type in .NET. The ObjectQuery type represents a query that can be executed against the conceptual model.

Using Query Builder

An ObjectQuery can be constructed by using the available extension methods such as Where, OrderBy, Select etc.  The ObjectQuery always work with an ObjectContext (in this instance ContosoEntities). For example the following code block calls the Where extension method to build the query to return only entities from the Customers entity set where the Country property is Australia.

C# Code

using (ContosoEntities ent = new ContosoEntities())

{

    ObjectQuery<Customer> query = ent.Customers.Where("it.Country=@ctry");

    query.Parameters.Add(new ObjectParameter("ctry", "Australia"));

    List<Customer> res = query.ToList();

}

Using Linq to Entities

The entities in ADO.NET are Linq enabled. You can use the language integrated query (Linq) features available in .NET 3.5 to query data. The following code shows the same query we wrote earlier using Linq to entities.

C# Code

using (ContosoEntities ent = new ContosoEntities())

{

    string country = "Australia";

    List<Customer> res = (from c in ent.Customers where c.Country == country select c).ToList();

}

We can also retrieve only a few properties of the Customer entity by using anonymous types and type inference feature in C# 3.0. For example the following query retrieves only the Name and the Country of CorporateCustomer instances:

using (ContosoEntities ent = new ContosoEntities())

{

    var res = (from c in ent.Customer where c is CorporateCustomer select new { c.Name, c.Country }).ToList();

}

The above code will select Customer entity instances that are of the type CorporateCustomer. The res variable will hold a reference to a list of anonymous type instances that has the Name and Country properties. You can also use the query builder methods to retrieve few properties of entity instances.

Using Entity SQL

Entity SQL is a SQL like query language that can be used to query data. Unlike SQL, Entity SQL uses entities, property names and associations defined in the conceptual schema in retrieving data. The following code block shows the query that we wrote using query builder and Linq to entities written using Entity SQL.

C# Code

using (ContosoEntities ent = new ContosoEntities())

{

    ObjectQuery<Customer> query = new ObjectQuery<Customer>("SELECT VALUE c FROM ContosoEntities.Customer as c WHERE c.Country=@ctry", ent);

    query.Parameters.Add(new ObjectParameter("ctry", "Australia"));

    List<Customer> res = query.ToList();

}

 

You can retrieve few properties of your entity instances similar to how we did using Linq to entities. But when using Entity SQL the results can be returned as instances of the type DbDatRecord.

C# Code:

using (ContosoEntities ent = new ContosoEntities())

{

    ObjectQuery<DbDataRecord> query = new ObjectQuery<DbDataRecord>("SELECT c.Name,c.City FROM ContosoEntities.Customer as c WHERE c.Country=@ctry", ent);

    query.Parameters.Add(new ObjectParameter("ctry", "Australia"));

    foreach (DbDataRecord item in query)

    {

        string name = item.GetString(0);

        string city = item.GetString(1);

        //process data

    }

}

 

Using Stored Procedures

If you do not want to rely on the dynamic SQL statements generated by the Entity Framework, you can create your own stored procedures and map them as functions. You can use these functions to query data. For example in the mapping files we had a stored procedure named SelectByCountry mapped to a function with the same name. We can directly call the function from our code to query data:

C# Code

using (ContosoEntities ent = new ContosoEntities())

{

    List<Customer> res = ent.SelectByCountry("Australia").ToList();

}

Updating data

Updating entities retrieved happens through the ObjectContext. The ObjectContext manages state changes on the entity set (inserts, updates and deletes). When the entity set needs to be updated with the data store, you can call the SaveChanges method of the ObjectContext class. This method would execute the required insert, update and delete statements specific to the data store based on whether the entity instances were newly created or updated or deleted.

C# Code:

using (ContosoEntities ent = new ContosoEntities())

{

    Customer c1 = ent.Customer.First(c => c.ID == 1);

    c1.Name = "Altered";

    Customer c2 = ent.Customer.First(c => c.ID == 2);

    ent.DeleteObject(c2);

    Customer c3 = new Customer();

    c3.Name = "Customer 3";

    //Set other properties for c3

    ent.AddToCustomer(c3);

    ent.SaveChanges();

}

The above code will update the Customer entity instance c1, delete c2 and insert the instance c3 as a new entity to the data store. All the inserts, updates and deletes would occur when the SaveChanges method is invoked.

While updating data, the Entity Framework uses optimistic concurrency. Rows are not locked when entities are retrieved, but at the time of updating it checks whether data was changed. You can control the properties of the entity that will be part of the concurrency check by setting the Concurrency Mode to Fixed. If the Concurrency Mode for a property of an entity is set to fixed then the auto-generated SQL statement would compare the original value that was retrieved with the current value in the data store. If there are any conflicts, an exception would be thrown.

If you do not wish to use the auto-generated SQL statements for persisting changes, you can define your own stored procedures for inserting updating and deleting your entity instances. Once these stored procedures are defined as functions in the storage schema you can map them in the mapping schema to be used by the ObjectContext for performing inserts, updates and deletes:

<EntityTypeMapping TypeName="ContosoModel.Customer">

  <ModificationFunctionMapping>

    <InsertFunction FunctionName="ContosoModel.Store.InsertCustomer">

      <ScalarProperty Name="ID" ParameterName="id" />

      <!-- Other properties mapped to parameters-->

    </InsertFunction>

    <UpdateFunction FunctionName="ContosoModel.Store.UpdateCustomer">

      <ScalarProperty Name="ID" ParameterName="id" Version="Current" />

      <!-- Other properties mapped to parameters-->

    </UpdateFunction>

    <DeleteFunction FunctionName="ContosoModel.Store.DeleteCustomer">

      <!-- Other properties mapped to parameters-->

      <ScalarProperty Name="ID" ParameterName="id" />

    </DeleteFunction>

  </ModificationFunctionMapping>

</EntityTypeMapping>

The above mapping indicates that we want to use the stored procedures defined as functions in the storage schema to be used for inserts, updates and deletes for the Customer entity.

Using the Entity Client Data Provider

The Entity Client Data Provider is an ADO.NET provider for your ADO.NET Entity Framework. The Entity Client Data Provider is built on top of the ADO.NET provider model. This allows you to work with ADO.NET objects that you are familiar with when working with other ADO.NET provides. For example we can run a query and retrieve data through a data reader as follows:

C# Code:

EntityConnection con = new EntityConnection();

con.ConnectionString = @"metadata=res://*/Contoso.csdl|res://*/Contoso.ssdl | res://*/Contoso.msl;provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;Initial Catalog=Contoso;Integrated Security=True;MultipleActiveResultSets=True'";

con.Open();

string sql = "SELECT c.Name,c.City FROM ContosoEntities.Customer as c WHERE c.Country=@ctry";

EntityCommand cmd = new EntityCommand(sql, con);

cmd.Parameters.Add(new EntityParameter("ctry", DbType.String)).Value = "Australia";

EntityDataReader rd = cmd.ExecuteReader(CommandBehavior.SequentialAccess);

while (rd.Read())

{

    string name = rd.GetString(0);

    string city = rd.GetString(1);

    //process record

}

rd.Close();

con.Close();

 

The above code creates an EntityConnection object and sets the connection string. The connection string for the Entity Client provider refers to the schema files, the database provider to use and the connection string to the database. An EntityCommand object uses an Entity SQL statement and the EntityConnection object to execute a query that returns an EntityDataReader instance. The data can be retrieved from the EntityDataReader instance.

Summary

The ADO.NET Entity Framework provides a framework and gives life to otherwise static entity data models. Conceptual entities designed in the development life cycle can be mapped to data stores. This allows an application developer to work with an object oriented model, and a database developer to work with a relational model.

Further Reading

    Amirthalingam Prasanna

    Author profile:

    Prasanna is a software engineer, technical author and trainer with many years of development and consulting experience in the software development industry. He is a Microsoft MVP in the Visual developer category, and a MCPD on enterprise application development. He has authored many articles and has worked on content creation for many Microsoft certification exams and courses. He is also a frequent speaker at Microsoft technology conferences and events. You can read his blog at www.prasanna.ws and e-mail him at feedback@prasanna.ws

    Search for other articles by Amirthalingam Prasanna

    Rate this article:   Avg rating: from a total of 113 votes.


    Poor

    OK

    Good

    Great

    Must read
    Have Your Say
    Do you have an opinion on this article? Then add your comment below:
    You must be logged in to post to this forum

    Click here to log in.


    Subject: Great intro the entity framework
    Posted by: Anonymous (not signed in)
    Posted on: Wednesday, May 28, 2008 at 10:29 AM
    Message: Great article. Keep this series going! Can you show a 3.5 sp1 beta example and explain how to have your Datalayer cross a wcf boundary with entity framework?

    Subject: Otay
    Posted by: Anonymous (not signed in)
    Posted on: Wednesday, May 28, 2008 at 11:34 AM
    Message: Maybe I'm just getting too old for this stuff (a good possibility), but I for one am getting tired of things like this in which there are umpteen different ways to do things. Note that I am not criticizing you, the author - I appreciate your effort in publishing the article. What would be nice is some context as to what is the "best" way to do things depending on certain factors, i.e., performance. Maybe it is in fact my age that I am starting to have an adverse reaction to having to learn four or five different new "syntaxes" for accessing data with every freakin' release of .NET. It just gets tiresome after a while.

    Subject: Otay
    Posted by: Anonymous (not signed in)
    Posted on: Wednesday, May 28, 2008 at 11:48 AM
    Message: Maybe I'm just getting too old for this stuff (a good possibility), but I for one am getting tired of things like this in which there are umpteen different ways to do things. Note that I am not criticizing you, the author - I appreciate your effort in publishing the article. What would be nice is some context as to what is the "best" way to do things depending on certain factors, i.e., performance. Maybe it is in fact my age that I am starting to have an adverse reaction to having to learn four or five different new "syntaxes" for accessing data with every freakin' release of .NET. It just gets tiresome after a while.

    Subject: oops
    Posted by: Anonymous (not signed in)
    Posted on: Wednesday, May 28, 2008 at 11:52 AM
    Message: Darn refresh button - Sorry about the double post. I'll skeedaddle now so it doesn't happen again. And by the way, all you young turks can feel free to diss my remarks about the pace of things changing. Sometimes I think I'm keeping up and other times I think there might actually be something to the old dogs / new tricks saying. Whatever - it's not like it's life and death like what our troops are having to deal with :)

    Subject: Re: Teaching the old dogs
    Posted by: Phil Factor (view profile)
    Posted on: Wednesday, May 28, 2008 at 12:47 PM
    Message: The Cribsheet series is meant for folks like 'Otay'. 'For things you need to know rather than the things you want to know'. One of the reasons for this article is that Entity Framework is here, it is important, and DBAs can use the facts in this article to argue back when the Young Turks demand table level access on the baseless and absurd myth that Entity Framework requires it. Knowledge is Strength.

    Subject: Performance?
    Posted by: Steve (view profile)
    Posted on: Wednesday, May 28, 2008 at 9:23 PM
    Message: Having entity framework means we can code faster than ever. Indeed, it has performance drawback, but with modern hardware it should not be an issue though. As a return, still we can code faster than ever, don't have to spend most of the time dealing with data, mapping it to the class, and yadda yadda..

    Just my 2 cents.

    Subject: Performance?
    Posted by: Steve (view profile)
    Posted on: Wednesday, May 28, 2008 at 10:39 PM
    Message: Having entity framework means we can code faster than ever. Indeed, it has performance drawback, but with modern hardware it should not be an issue though. As a return, still we can code faster than ever, don't have to spend most of the time dealing with data, mapping it to the class, and yadda yadda..

    Just my 2 cents.

    Subject: Re: Performance?
    Posted by: Prasanna (view profile)
    Posted on: Wednesday, May 28, 2008 at 11:05 PM
    Message: I agree. Working with a ADO.NET provider directly might be faster. But considering the performance I can immediately think of only two concerns:
    Is the SQL queries generated are optmized?
    -We have an alternative here to map our SPs.
    Projection of results into objects?
    -We do projection of results even when we use datasets. And using strongly typed objects would be faster since there is no weight of XML.

    What I like about EF is the flexibility. For example I can rely on dynamic SQL for CUD operations then I can alter it to use SPs if needed without changing code and by just changing the schema files

    Subject: Modern Software with Modern Hardware
    Posted by: Sathiya (not signed in)
    Posted on: Thursday, May 29, 2008 at 12:57 AM
    Message: Mr.Prasanna has given chain knowledge to start development with Entity Framework.

    It is incredible article, if it helps to get practical knowledge about Entity framework within 30 minutes.

    When we read his articles we feel it is easy, but, when you apply to work the content of the article, you will feel that he has done a fantastic job for his fans :).

    Thanks again for maintaining “How to feed”

    Sathiyaseelan Arulanandam

    Subject: Looks like program elegance, and simplicity have been forgotten...
    Posted by: Anonymous (not signed in)
    Posted on: Sunday, June 22, 2008 at 1:58 AM
    Message: This looks like another layer between the database and the objects, that does not much value.

    It is in my experience better to code any mapping between the database artifacts and the object world. That makes the overall application easy to understand, maintain, and enhance.

    It is relatively more work, but in the end it may lead to more elegant and simple programs.

    Subject: Looks like program elegance, and simplicity have been forgotten...
    Posted by: Anonymous (not signed in)
    Posted on: Sunday, June 22, 2008 at 2:49 AM
    Message: This looks like another layer between the database and the objects, that does not much value.

    It is in my experience better to code any mapping between the database artifacts and the object world. That makes the overall application easy to understand, maintain, and enhance.

    It is relatively more work, but in the end it may lead to more elegant and simple programs.

    Subject: Re: Looks like program elegance, and simplicity have been forgotten
    Posted by: Phil Factor (view profile)
    Posted on: Sunday, June 22, 2008 at 11:25 AM
    Message: Sometimes you can't choose the platform you are coding to. DBAs, too, don't often get much choice in development standards. We all need to know about Entity Framework, simply because it is there. That's the purpose of a cribsheet. I think Prasanna has done a good job in showing how it can be used sensibly if there is a will to do so.

    Subject: Simplicity
    Posted by: Robert (view profile)
    Posted on: Wednesday, July 23, 2008 at 8:03 AM
    Message: All something Codesmith and netTiers can do with out the levels and without hand coding. They generate objects that can be made into DLLs for you program, not this XML garbage.

    The article was good. Not critical of it.

    Being one of the Old Dogs myself, I am also tired. Keeping up with all of the "better" ways of doing things is very tiring. And, just when you think you reached the goal, they move the finish line.

     

    Top Rated

    Acceptance Testing with FitNesse: Multiplicities and Comparisons
     FitNesse is one of the most popular tools for unit testing since it is designed with a Wiki-style... Read more...

    Acceptance Testing with FitNesse: Symbols, Variables and Code-behind Styles
     Although FitNesse can be used as a generic automated testing tool for both applications and databases,... Read more...

    Acceptance Testing with FitNesse: Documentation and Infrastructure
     FitNesse is a popular general-purpose wiki-based framework for writing acceptance tests for software... Read more...

    TortoiseSVN and Subversion Cookbook Part 11: Subversion and Oracle
     It is only recently that the tools have existed to make source-control easy for database developers.... Read more...

    TortoiseSVN and Subversion Cookbook Part 10: Extending the reach of Subversion
     Subversion provides a good way of source-controlling a database, but many operations are best done from... Read more...

    Most Viewed

    A Complete URL Rewriting Solution for ASP.NET 2.0
     Ever wondered whether it's possible to create neater URLS, free of bulky Query String parameters?... Read more...

    Visual Studio Setup - projects and custom actions
     This article describes the kinds of custom actions that can be used in your Visual Studio setup project. Read more...

    .NET Application Architecture: the Data Access Layer
     Find out how to design a robust data access layer for your .NET applications. Read more...

    Calling Cross Domain Web Services in AJAX
     The latest craze for mashups involves making cross-domain calls to Web Services from APIs made publicly... Read more...

    Web Parts in ASP.NET 2.0
     Most Web Parts implementations allow users to create a single portal page where they can personalize... Read more...

    Why Join

    Over 400,000 Microsoft professionals subscribe to the Simple-Talk technical journal. Join today, it's fast, simple, free and secure.