What is the basic difference between ADO.NET and Entity Framework?

Technology CommunityCategory: ADO.NETWhat is the basic difference between ADO.NET and Entity Framework?
VietMX Staff asked 3 years ago

ADO.NET Entity Framework is an ORM (object-relational mapping) which creates a higher abstract object model over ADO.NET components. ADO.NET is a layer closer to the database (datatables, datasets and etc…). The main and the only benefit of EF is it auto-generates code for the Model (middle layer), Data Access Layer, and mapping code, thus reducing a lot of development time. Consider the following example:

ADO.NET:

DataTable table = adoDs.Tables[0];
for (int j = 0; j < table.Rows.Count; j++)
{
    DataRow row = table.Rows[j];

    // Get the values of the fields
    string CustomerName =
        (string)row["Customername"];
    string CustomerCode =
        (string)row["CustomerCode"];
}

EF:

foreach (Customer objCust in obj.Customers)
{}