public static List <Match> ToDb(this NHibernate.ISession session, IList <Entity.NHibernate.EventParent> competitions, DateTime dt) { PrepareForDb(ref competitions); List <Match> matches = new List <Match>(); // save both stores, this saves everything else via cascading // save both stores, this saves everything else via cascading var gcomps = competitions.GroupBy(_ => _.Key); // populate the database foreach (var competition in gcomps) { using (var transaction = session.BeginTransaction()) { var fcompetition = competition.First(); var gmatches = gcomps.SelectMany(_ => _.SelectMany(c => c.Matches.Where(m => new DateTime(m.Start) < dt))).ToList(); //foreach (var match in gmatches) // match.EventParent = fcompetition; if (session.QueryOver <Entity.NHibernate.EventParent>().RowCount() == 0 || session.QueryOver <Entity.NHibernate.EventParent>().Where(x => x.Key == competition.Key).RowCount() == 0) { session.SaveOrUpdate(competition.First()); } //var gmatches = gcomps.SelectMany(_ => _.SelectMany(c => c.Matches)); //foreach (var m in gmatches) // m.EventParent = fcompetition; var gml = gmatches.ToList(); matches.AddRange(gml); session.ToDb(gml); transaction.Commit(); } } return(matches); }
public static bool ToDb(this NHibernate.ISession session, IList <Entity.NHibernate.EventParent> competitions) { // save both stores, this saves everything else via cascading var gcomps = competitions.GroupBy(_ => _.Key); foreach (var competition in gcomps) { var fcompetition = competition.First(); var competitionId = fcompetition.Id; if (session.QueryOver <Entity.NHibernate.EventParent>().RowCount() == 0 || session.QueryOver <Entity.NHibernate.EventParent>().Where(x => x.Key == competition.Key).RowCount() == 0) { session.SaveOrUpdate(competition.First()); } var gmatches = gcomps.SelectMany(_ => _.SelectMany(c => c.Matches)); session.ToDb(gmatches.ToList()); } return(true); }