コード例 #1
0
        public void UpdateAdvert(Advert ad)
        {
            var existing = _ctx.Adverts.SingleOrDefault(em => em.Id == ad.Id);

            if (existing != null)
            {
                _ctx.Entry(existing).State = EntityState.Detached;
                _ctx.Adverts.Attach(ad);
                _ctx.Entry(ad).State = EntityState.Modified;
                _ctx.SaveChanges();
            }
        }
コード例 #2
0
 //----------------------------- A D V E R T S -----------------------------------
 public Advert CreateAdvert(Advert ad)
 {
     _ctx.Adverts.Add(ad);
     _ctx.SaveChanges();
     return(ad);
 }