async Task <List <IEntity> > LoadFromDatabase()
        {
            List <IEntity> result;

            if (NeedsTypeResolution())
            {
                var queries = EntityFinder.FindPossibleTypes(EntityType, mustFind: true)
                              .Select(t => CloneFor(t))
                              .Select(q => q.Provider.GetList(q));

                result = await queries.SelectManyAsync(x => x).ToList();
            }
            else
            {
                result = await Provider.GetList(this).ToList();
            }

            if (OrderByParts.None())
            {
                // TODO: If the entity is sortable by a single DB column, then automatically add that to the DB call.
                result.Sort();
            }

            await LoadIncludedAssociations(result);

            return(result);
        }
        static List <IDataProvider> ResolveDataProviders(Type baseType)
        {
            var factories = AssemblyProviderFactories.Where(f => f.Value.SupportsPolymorphism() && f.Key.References(baseType.Assembly)).ToList();

            var result = new List <IDataProvider>();

            foreach (var f in factories)
            {
                result.Add(f.Value.GetProvider(baseType));
            }

            foreach (var type in EntityFinder.FindPossibleTypes(baseType, mustFind: factories.None()))
            {
                result.Add(GetProvider(type));
            }

            return(result);
        }
        List <IDataProvider> ResolveDataProviders()
        {
            var factories = Context.Current.Database().AssemblyProviderFactories
                            .Where(f => f.Value.SupportsPolymorphism())
                            .Where(f => f.Key.References(EntityType.GetTypeInfo().Assembly)).ToList();

            var result = new List <IDataProvider>();

            foreach (var f in factories)
            {
                result.Add(f.Value.GetProvider(EntityType));
            }

            foreach (var type in EntityFinder.FindPossibleTypes(EntityType, mustFind: factories.None()))
            {
                result.Add(Context.Current.Database().GetProvider(type));
            }

            return(result);
        }
Exemple #4
0
        async Task <List <IEntity> > LoadFromDatabase()
        {
            List <IEntity> result;

            if (NeedsTypeResolution())
            {
                var queries = EntityFinder.FindPossibleTypes(EntityType, mustFind: true)
                              .Select(t => CloneFor(t))
                              .Select(q => q.Provider.GetList(q));

                result = await queries.SelectManyAsync(x => x).ToList();
            }
            else
            {
                result = await Provider.GetList(this).ToList();
            }

            foreach (var item in result)
            {
                await Entity.Services.RaiseOnLoaded(item);
            }

            if (OrderByParts.None() && !SkipAutoSortAttribute.HasAttribute(EntityType))
            {
                if (EntityType.Implements <ISortable>())
                {
                    result = result.OrderBy(x => (x as ISortable).Order).ToList();
                }
                else
                {
                    result.Sort();
                }
            }

            await LoadIncludedAssociations(result);

            return(result);
        }