How will you differentiate ADO.NET from Entity Framework?

 


ADO.NET

public class UserRepository

   {

        public DataSet GetAllUsersList()

        {

              DataSet ds = new DataSet(); // Initializes disconnected dataset to fetch results

          

                //Create and initialize the connection using connection string

              using (SqlConnection sqlConn = SqlConnection ("DataSource=localhost;

  Initial Catalog=TestDB; User ID=sa;Password=admin;"))

                {

                  

                        sqlConn.Open(); //Open connection

           string sql = "select * from tblusers"; // sql query to access user from table

                         SqlCommand sqlCmd = new SqlCommand(sql, sqlConn);

                  

                         sqlCmd.CommandType = CommandType.Text; // Define Command Type      

         

                         SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCmd);

                   

                         sqlAdapter.Fill(ds); //Get the data in disconnected mode

                }                          

               return ds; // return dataset result

        }

    }

 

EF

public class UserRepository

    {

        public static void Main(string[] args)

        {

           // Initializes the dbContext class User Entity

            using (var userContextDB = new UserContext())

            {

                // Create a new user object

                var user = new User() { UserID = "USER-01" };

      

                // Call Add Command

                userContextDB.User.Add(user);

 

                // Execute the save command to make changes

                userContextDB.SaveChanges();               

            }

        }

    }

 

 

Post a Comment

Previous Post Next Post