Exemple #1
0
        public static List <Match> ToDb(this OddsContext 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)
            {
                var fcompetition  = competition.First();
                var competitionId = fcompetition.Id;

                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.EventParents.Find(competitionId) == null)
                {
                    session.EventParents.Add(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);
            }


            session.BatchSaveChanges();

            return(matches);
        }
Exemple #2
0
        public static bool ToDb(this OddsContext 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.EventParents.Find(competitionId) == null)
                {
                    session.EventParents.Add(competition.First());
                }

                var gmatches = gcomps.SelectMany(_ => _.SelectMany(c => c.Matches));

                session.ToDb(gmatches.ToList());

                session.BatchSaveChanges();
            }

            return(true);
        }