Пример #1
0
    protected void DeleteRecord(object sender, EventArgs e)
    {
        using (DemoDatabaseDB db = new DemoDatabaseDB())
        {
            PersonalDetail p = db.PersonalDetails.Where(pp => pp.AutoId.Equals(52)).FirstOrDefault();

            db.PersonalDetails.DeleteObject(p);

            db.SaveChanges();
        }

        lblMessage.Text = "Record delete from the database successfully!";
    }
Пример #2
0
    protected void SaveUsingLinqWithTransaction(object sender, EventArgs e)
    {
        using (TransactionScope scope = new TransactionScope())
        {
            try
            {
                using (DemoDatabaseDB db = new DemoDatabaseDB())
                {
                    PersonalDetail p = new PersonalDetail()
                    {
                        Active    = true,
                        Age       = int.MaxValue,
                        FirstName = "firstnamne",
                        LastName  = "lastname"
                    };
                    db.PersonalDetails.AddObject(p);
                    db.SaveChanges();

                    DemoDatabaseModel.Menu m = new DemoDatabaseModel.Menu()
                    {
                        MenuDescription = "description1",
                        MenuName        = "Menu1Menu1Menu1Menu1Menu1Menu1Menu21", //Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1Menu1",
                        MenuUrl         = "http://www.fundooVideo.com/",
                        ParentMenuId    = 1,
                        MenuId          = 127
                    };


                    db.Menus.AddObject(m);
                    db.SaveChanges();
                }
                scope.Complete();
            }
            catch (Exception ee)
            {
                Response.Write(ee.ToString());
            }
        }
    }
Пример #3
0
    protected void UpdateRecord(object sender, EventArgs e)
    {
        using (DemoDatabaseDB db = new DemoDatabaseDB())
        {
            PersonalDetail p = db.PersonalDetails.Where(pp => pp.AutoId.Equals(52)).FirstOrDefault();

            p.Active    = false;
            p.Age       = 30;
            p.FirstName = "Ranjit modified";
            p.LastName  = "Mahato modified";

            db.SaveChanges();
        }

        lblMessage.Text = "Record updated to the database successfully!";
    }
Пример #4
0
    protected void InsertRecord(object sender, EventArgs e)
    {
        PersonalDetail p = new PersonalDetail()
        {
            Active    = true,
            Age       = 20,
            FirstName = "Ranjit",
            LastName  = "Mahato"
        };

        using (DemoDatabaseDB db = new DemoDatabaseDB())
        {
            db.PersonalDetails.AddObject(p);
            db.SaveChanges();
        }

        lblMessage.Text = "Record added to the database successfully!";
    }