/// <summary>
        /// Link a queryable entity list with values/relations to produce a list of packaged entities
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="queryable"></param>
        /// <returns></returns>
        public static async Task <List <EntityPackage> > LinkAsync(this IEntityProvider provider, IQueryable <Entity> queryable)
        {
            //Performance test this sometime
            var entities = await provider.GetListAsync(queryable);

            //Oops, there's nothing. Don't bother (we don't need to query the WHOLE database for no entities)
            if (entities.Count == 0)
            {
                return(new List <EntityPackage>());
            }

            var ids    = entities.Select(x => x.id).ToList();
            var values = await provider.GetEntityValuesAsync(new EntityValueSearch()
            {
                EntityIds = ids
            });                                                                                            //Will this stuff be safe?

            var relations = await provider.GetEntityRelationsAsync(new EntityRelationSearch()
            {
                EntityIds2 = ids
            });                                                                                                      //Will this stuff be safe?

            return(entities.Select(x => new EntityPackage()
            {
                Entity = x,
                Values = values.Where(y => y.entityId == x.id).ToList(),
                Relations = relations.Where(y => y.entityId2 == x.id).ToList()
            }).ToList());
        }
        public static async Task <EntityRelation> FindRelationByIdAsync(this IEntityProvider provider, long id)
        {
            var search = new EntityRelationSearch();

            search.Ids.Add(id);
            return((await provider.GetEntityRelationsAsync(search)).OnlySingle());
        }
Esempio n. 3
0
        public async Task <ActionResult <TestData> > TestGet()
        {
            var entities = await provider.GetEntitiesAsync(new EntitySearch());                 //This should get all?

            var values = await provider.GetEntityValuesAsync(new EntityValueSearch());          //This should get all?

            var relations = await provider.GetEntityRelationsAsync(new EntityRelationSearch()); //This should get all?

            return(new TestData()
            {
                EntityCount = entities.Count,
                ValueCount = values.Count,
                RelationCount = relations.Count
            });
        }
        /// <summary>
        /// Retrieve relations that "own" the given entities (one to many, us being one of the many). For instance, if
        /// a user owns content, the content id will be entity2, and that is what we get.
        /// </summary>
        /// <param name="items"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public async Task <Dictionary <long, List <EntityRelation> > > GetSortedRelations <T>(IEnumerable <T> items) where T : BaseSystemObject
        {
            var relations = await provider.GetEntityRelationsAsync(new EntityRelationSearch()
            {
                EntityIds2 = items.Select(x => x.id).ToList()
            });

            var result = items.Where(x => x.id != 0).ToDictionary(x => x.id, y => new List <EntityRelation>());

            result.Add(0, new List <EntityRelation>());

            foreach (var relation in relations)
            {
                result[relation.entityId2].Add(relation);
            }

            return(result);
        }