Hi,
Could you please help me to understand the difference between ADO.Net and Entity framework?
I am finding difficulty to explain this in interview.
Thank you!!
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vincent Maverick DuranoRank #238 · 10.3K reputationPosted Nov 6, 2018, 10:25 AM EST
Tejas TrivediRank #1,247 · 1.4K reputationPosted Oct 4, 2018, 6:35 PM EDT
Puneet KankarRank #446 · 5.6K reputationPosted Nov 5, 2018, 10:11 PM EST
Sreekanth ReddyRank #726 · 3.2K reputationPosted Nov 8, 2018, 7:49 PM EST
Farhan AhmedRank #73 · 25K reputationPosted Oct 4, 2018, 6:44 PM EDT
Ankusha Rana27 reputationPosted Nov 4, 2018, 9:45 PM EST
Laxmidhar SahooRank #383 · 6.6K reputationPosted Nov 9, 2018, 6:07 PM EST
Ankusha Rana27 reputationPosted Nov 12, 2018, 11:40 PM EST
ADO.NET entity is an ORM (object relational mapping) which creates a higher abstract object model over ADO.NET components. So rather than getting into dataset, datatables, command, and connection objects as shown in the below code, you work on higher level domain objects like customers, suppliers, etc.
EF is built at the top of ADO .net, so it can’t be faster but still, there are some great reasons to use EF over ADO. Net.
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 11, 2019, 6:14 AM EST
geetha geethaRank #7,130 · 248 reputationPosted Nov 3, 2021, 6:53 AM EDT
ADO.NET:
ADO.NETstands for ActiveX Data Object, provides a bridge between relational and non-relational systems. It is a great technology after traditional ADO, which gives an advantage to create everything from scratch and havea full access control of a database in the application. You can get data from ADO.NET in disconnected mode and can serve a large number of connections without compromising on the performance of an application.InADO.NET, you can access and modify data stored in data sources such as Oracle, MS SQL Server, MySQL, and XML. It has a set of classes and data providers that are equivalent to OLE DB, ODBC and JDBC drivers. It mainly uses two namespaces, System.Data.dll and System.Xml.dll that supports the interaction between client and database.
Example for fetching data in ADO. Net:
namespace sample ADONET
{
public class UserRepository
{
public DataSet GetAllUsersList()
{
DataSet ds = new DataSet();
try
{
using (SqlConnection sqlConn =
SqlConnection ("DataSource=localhost;Initial Catalog=TestDB;
User ID=sa;Password=******;"))
{
//Open connection
sqlConn.Open();
string sql = "select * from tblusers";
SqlCommand sqlCmd = new SqlCommand(sql, sqlConn);
sqlCmd.CommandType = CommandType.Text;
SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCmd);
sqlAdapter.Fill(ds);
}
}
catch (Exception ex)
{
// Log exception in log file or in database
}
return ds;
}
}
}
Entity Framework:
Entity framework is an Object Relational Mapping (ORM) framework that offers an automated mechanism to developers for storing and accessing the data in the database.Entity Framework will execute the relevant query in the database and then materialize results into instances of your domain objects for you to work within your app.ntity Framework can generate the necessary database commands for reading or writing data in the database and execute them for you.
Fetching data in Entity Framework:
namespace Sample EF
{
public class UserRepository
{
public static void Main(string[] args)
{
using (var userContextDB = new UserContext())
{
var user = new User() { UserID = "USER-01" };
userContextDB.User.Add(user);
userContextDB.SaveChanges();
}
}
}
}
Sam HobbsRank #107 · 20.5K reputationPosted Feb 3, 2022, 7:19 PM EST
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Feb 4, 2022, 1:30 AM EST