public static void Main() { var db = new ArtistsDbContext(); var artist = new Artist { Name = "Pesho", Gender = GenderType.Female }; db.Artists.Add(artist); db.SaveChanges(); Console.WriteLine(db.Artists.Count()); }
static void Main(string[] args) { Database.SetInitializer(new MigrateDatabaseToLatestVersion <ArtistsDbContext, Configuration>()); IArtistsDbContext db = new ArtistsDbContext(); Artist artist = new Artist { Name = "Madona", Gender = GenderType.Female }; //db.Configuration.LazyLoadingEnabled = false; //db.Configuration.ValidateOnSaveEnabled = false; db.Artists.Add(artist); db.SaveChanges(); //db.Configuration.LazyLoadingEnabled = true; //db.Configuration.ValidateOnSaveEnabled = true; Console.WriteLine(db.Artists.Count()); }
public void UpdateTimeEvent(Events events) { using (var tran = _context.Database.BeginTransaction()) { var ev = _context.Artist_Events .Include(m => m.Artist) .Where(m => m.IdEvent == events.IdArtist) .Where(m1 => m1.IdEvent == events.IdEvent); if (ev == null) { tran.Rollback(); throw new EventOrArtistDoesNotExistException($"Event does not exist with id={events.IdEvent} or artist does not exist with id={events.IdArtist} "); } //ev.PerfomanceDate = events.PerfomanceDate; _context.SaveChanges(); tran.Commit(); } }
public int Commit() { return(_context.SaveChanges()); }