Exemplo n.º 1
0
        public DepartmentType(QueryFactoryHelper queryFactoryHelper, IDataLoaderContextAccessor dataLoaderContextAccessor)
        {
            Name = "Department";

            Field(h => h.DepartmentId).Description("DepartmentId");

            Field(h => h.Name, true).Description("Name");
        }
Exemplo n.º 2
0
        public CourseType(QueryFactoryHelper queryFactoryHelper, IDataLoaderContextAccessor dataLoaderContextAccessor)
        {
            Name = "Course";

            Field(h => h.CourseId).Description("CourseId");

            Field(h => h.Name, true).Description("Name");

            Field(h => h.DepartmentId, true).Description("DepartmentId");

            Field(h => h.Credits).Description("Credits");
        }
Exemplo n.º 3
0
        public DataQuery(QueryFactoryHelper queryFactoryHelper)
        {
            //this.AuthorizeWith("IsAuthenticatedPolicy");

            _queryFactoryHelper = queryFactoryHelper;

            Name = "Query";

            InitQuery <CourseType, Course>("Course");

            InitQuery <DepartmentType, Department>("Department");

            InitQuery <StudentType, Student>("Student");
        }
Exemplo n.º 4
0
        public void GetLocalIDsTest()
        {
            Include inc = new Include();

            inc.LocalKey = "key";
            string obj = "im the object";
            List <Dictionary <string, object> > dynamicResult = new List <Dictionary <string, object> >();

            dynamicResult.Add(new Dictionary <string, object>());
            dynamicResult[0].Add(inc.LocalKey, obj);
            List <object> result = QueryFactoryHelper.GetLocalIDs(dynamicResult, inc);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            string resultVal = result[0] as string;

            Assert.AreEqual(obj, resultVal);
        }
Exemplo n.º 5
0
        public StudentType(QueryFactoryHelper queryFactoryHelper, IDataLoaderContextAccessor dataLoaderContextAccessor)
        {
            Name = "Student";

            Field(h => h.Id).Description("Id");

            Field(h => h.Surname, true).Description("Surname");

            Field(h => h.Forename, true).Description("Forename");

            Field(h => h.CourseId).Description("CourseId");

            Field <CourseType, Course>()
            .Name("course")
            .Description("Related course")
            .ResolveAsync(context =>
            {
                Func <IEnumerable <CompositeKey>, CancellationToken, Task <IDictionary <CompositeKey, Course> > > batchLoaderLogic = async(ids, cancelToken) =>
                {
                    var aggregatedResults = await ChildQueryHelper.Get <Course>("Course", queryFactoryHelper, ids);
                    var dict = new Dictionary <CompositeKey, Course>(new CompositeKey.MyEqualityComparer());
                    foreach (var r in aggregatedResults)
                    {
                        var fkFields = new Dictionary <string, object>()
                        {
                            { "CourseId", r.CourseId }
                        };
                        var key = new CompositeKey(fkFields);
                        dict.TryAdd(key, r);
                    }

                    return(dict);
                };

                var dataLoader   = dataLoaderContextAccessor.Context.GetOrAddBatchLoader("Student_Course", batchLoaderLogic);
                var parentFields = new Dictionary <string, object>()
                {
                    { "CourseId", context.Source.CourseId }
                };
                return(dataLoader.LoadAsync(new CompositeKey(parentFields)));
            });
        }
Exemplo n.º 6
0
        public static async Task <IEnumerable <TEntity> > Get <TEntity>(string tableName, QueryFactoryHelper queryFactoryHelper, IEnumerable <CompositeKey> ids)
        {
            var queryFactory = queryFactoryHelper.GetQueryFactory();

            var whereIn = DataLoaderUtility.GetWhereIn(ids);

            const float maximumIdCount    = 1000;
            var         idCount           = whereIn.First().Value.Length;
            var         aggregatedResults = new List <TEntity>();

            var totalPages = Math.Ceiling(idCount / maximumIdCount);

            for (var page = 0; page < totalPages; page++)
            {
                var batchedCompositeIds = new Dictionary <string, string[]>();

                foreach (var(key, value) in whereIn)
                {
                    batchedCompositeIds.Add(key,
                                            value.Skip((int)(page * maximumIdCount)).Take((int)maximumIdCount).ToArray());
                }

                var query = queryFactory
                            .Query(tableName);

                foreach (var(field, fieldIds) in batchedCompositeIds)
                {
                    query.WhereIn(field, fieldIds);
                }
                var results = await query.GetAsync <TEntity>();

                aggregatedResults.AddRange(results);
            }

            return(aggregatedResults);
        }