Esempio n. 1
0
        public IEnumerable <T> GetAll(string[] includes = null)
        {
            //HANDLE INCLUDES FOR ASSOCIATED OBJECTS IF APPLICABLE
            if (includes != null && includes.Count() > 0)
            {
                var query = dataContext.Set <T>().Include(includes.First());
                foreach (var include in includes.Skip(1))
                {
                    query = query.Include(include);
                }
                return(query.AsQueryable());
            }

            return(dataContext.Set <T>().AsQueryable());
        }
Esempio n. 2
0
        static EntityScriptUtil()
        {
            EntityScriptLazyLoader = new Lazy <ConcurrentDictionary <Type, List <EntityRuleScript> > >(
                () =>
            {
                using (var db = new FrameworkDbContext())
                {
                    var esGroups =
                        from es in db.Set <EntityRuleScript>().ToList()
                        where es.TargetType != null
                        group es by es.TargetType
                        into esGroup
                        select esGroup;

                    var dictionary = esGroups.ToDictionary(esg => esg.Key, esg => esg.ToList());
                    var cach       = new ConcurrentDictionary <Type, List <EntityRuleScript> >(dictionary);
                    return(cach);
                }
            }
                );

            EntityNumberingLazyLoader = new Lazy <ConcurrentDictionary <Type, List <EntityNumbering> > >(
                () =>
            {
                using (var db = new FrameworkDbContext())
                {
                    var enGroups =
                        from en in db.Set <EntityNumbering>().ToList()
                        where en.TargetType != null
                        group en by en.TargetType
                        into enGroup
                        select enGroup;

                    var dictionary = enGroups.ToDictionary(eng => eng.Key, eng => eng.ToList());
                    var cach       = new ConcurrentDictionary <Type, List <EntityNumbering> >(dictionary);
                    return(cach);
                }
            }
                );
        }
Esempio n. 3
0
        private long RunTest(string testName, List <DummyObject> pack, FrameworkDbContext db)
        {
            LogLine("");
            LogTime(string.Format("{0} test started for {1} items.", testName, pack.Count));

            Stopwatch stopwatch = Stopwatch.StartNew();

            for (var i = 0; i < pack.Count; i++)
            {
                var p = pack[i];
                db.Set <DummyObject>().Add(p);
                db.SaveChanges();
            }

            var total = stopwatch.ElapsedMilliseconds;

            long average = total / pack.Count;

            LogLine(string.Format("\tAverage: {0} ms.", average));

            return(average);
        }
Esempio n. 4
0
 protected BaseRepository(IDbFactory dbFactory)
 {
     DbFactory = dbFactory;
     dbSet     = DbContext.Set <T>();
 }
Esempio n. 5
0
        public static long GetNext(
            string sequenceName,
            string param1  = null,
            string param2  = null,
            string param3  = null,
            string param4  = null,
            string param5  = null,
            string usedFor = null
            )
        {
            using (var db = new FrameworkDbContext())
            {
                var seq = Cache.GetOrAdd(sequenceName, (seqName) =>
                {
                    var s = db.Set <EntitySequence>().FirstOrDefault(es => es.Name == seqName);

                    //if (s == null)
                    //{
                    //    var temp = db.Set<EntitySequence>().Create();
                    //    temp.Name = seqName;
                    //    temp.Description = $"Automatically created for: {usedFor}";
                    //    db.SaveChanges();
                    //}
                    return(s);
                });

                if (seq == null)
                {
                    throw new Exception($"Sequence is not defined: {sequenceName}");
                }

                var sameSequenceItems = db.Set <EntitySequenceItem>()
                                        .Where(si =>
                                               si.Param1 == param1 &&
                                               si.Param2 == param2 &&
                                               si.Param3 == param3 &&
                                               si.Param4 == param4 &&
                                               si.Param5 == param5);

                var maxValue =
                    sameSequenceItems.Any() ?
                    sameSequenceItems.Max(si => si.SeqValue) :
                    0;

                var esi = new EntitySequenceItem(true)
                {
                    SeqValue         = maxValue + 1,
                    EntitySequenceId = seq.Id,
                    CreationDateTime = DateTime.Now,
                    Param1           = param1,
                    Param2           = param2,
                    Param3           = param3,
                    Param4           = param4,
                    Param5           = param5,
                    UsedFor          = usedFor
                };


                db.Set <EntitySequenceItem>().Add(esi);
                db.SaveChanges();

                return(esi.SeqValue);
            }
        }
Esempio n. 6
0
        protected override void ExecuteImpl()
        {
            base.ExecuteImpl();

            var testPack = SelectedObject.Id;
            var test     = SelectedObject;


            stopwatch = Stopwatch.StartNew();


            int packSize = 100;

            test.PackSize = packSize;

            Log(string.Format("Creating test objects. Size: {0}", packSize));


            var pack1B =
                Enumerable.Range(1, packSize)
                .Select((i) => DummyObject.Create1B(testPack))
                .ToList();

            var pack1K =
                Enumerable.Range(1, packSize)
                .Select((i) => DummyObject.Create1K(testPack))
                .ToList();
            var pack10K =
                Enumerable.Range(1, packSize)
                .Select((i) => DummyObject.Create10K(testPack))
                .ToList();

            var pack100K =
                Enumerable.Range(1, packSize)
                .Select((i) => DummyObject.Create100K(testPack))
                .ToList();

            var pack1000K =
                Enumerable.Range(1, packSize)
                .Select((i) => DummyObject.Create1000K(testPack))
                .ToList();

            LogTime("Objects ready.");

            using (var db = new FrameworkDbContext())
            {
                test.AverageTime1B    = RunTest("1B", pack1B, db);
                test.AverageTime1K    = RunTest("1K", pack1K, db);
                test.AverageTime10K   = RunTest("10K", pack10K, db);
                test.AverageTime100K  = RunTest("100K", pack100K, db);
                test.AverageTime1000K = RunTest("1000K", pack1000K, db);

                var queryAll =
                    db.Set <DummyObject>()
                    .Where(d => d.TestPack == testPack);

                LogLine("");
                LogTime("Loading All started.");
                var  list     = queryAll.ToList();
                long loadTime = stopwatch.ElapsedMilliseconds;

                LogLine(string.Format("\tLoad Time:\t{0} ms", loadTime));
                test.LoadAllTime = loadTime;

                LogLine(string.Format("\tCount:\t{0}", list.Count));
                test.LoadAllCount = list.Count;
            }
        }