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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Muhammad Imran AnsariPosted Feb 4, 2022, 6:30 AM
Sam HobbsPosted Feb 4, 2022, 12:19 AM
geetha geethaPosted Nov 3, 2021, 10:53 AM
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();
}
}
}
}
Mageshwaran RPosted Nov 11, 2019, 11:14 AM
Ankusha RanaPosted Nov 13, 2018, 4:40 AM
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.
Laxmidhar SahooPosted Nov 9, 2018, 11:07 PM
Sreekanth ReddyPosted Nov 9, 2018, 12:49 AM
Vincent Maverick DuranoPosted Nov 6, 2018, 3:25 PM
Puneet KankarPosted Nov 6, 2018, 3:11 AM
Ankusha RanaPosted Nov 5, 2018, 2:45 AM
Farhan AhmedPosted Oct 4, 2018, 10:44 PM
Tejas TrivediPosted Oct 4, 2018, 10:35 PM