Prefetch Suggestion

Posts   
 
    
Evan
User
Posts: 67
Joined: 02-May-2012
# Posted on: 18-Apr-2013 16:26:00   

Hey, if you're looking for yet another version of defining a prefetch path, consider the following. I think it would catch all logical errors at compile time and has a nice, readable, fluent-like definition syntax. In particular it wouldn't require you to define variables or anything to do complex prefetch trees, and it enforces the paths match up.(from entity, to entity)


        public interface IFromPrefetch<F> where F : EntityBase2
        {
            
        }

        public class Prefetch<E> where E : EntityBase2
        {
            public Prefetch(params IFromPrefetch<E>[] subPaths)
            {
                this.SubPaths = subPaths;
            }

            public IEnumerable<IFromPrefetch<E>> SubPaths = null;
        }

        public class Prefetch<F, T> : IFromPrefetch<F> where F : EntityBase2 where T : EntityBase2
        {
            public Prefetch(params IFromPrefetch<T>[] subPaths)
            {
                this.SubPaths = subPaths;
            }
            public IEnumerable<IFromPrefetch<T>> SubPaths = null;
        }

        //sample generated code
        public static Prefetch<ColleagueEntity, CredentialEntity> Colleague_PrefetchCredential(
params IFromPrefetch<CredentialEntity>[] subPaths) 
        { 
            return new Prefetch<ColleagueEntity, CredentialEntity>(subPaths); 
        }
        
        public static Prefetch<ColleagueEntity, CounterPartyEntity> Colleague_PrefetchCounterParty(
params IFromPrefetch<CounterPartyEntity>[] subPaths) 
        { 
            return new Prefetch<ColleagueEntity, CounterPartyEntity>(subPaths); 
        }

        public static Prefetch<CredentialEntity, CredentialSettingEntity> Credential_PrefetchCredentialSetting(
params IFromPrefetch<CredentialSettingEntity>[] subPaths) 
        { 
            return new Prefetch<CredentialEntity, CredentialSettingEntity>(subPaths); 
        }

        //sample usage.(easy to read depth, not error-prone)
        public static Prefetch<ColleagueEntity> PrefetchCredentialCredentialSettingAndCounterParty()
        {
            return new Prefetch<ColleagueEntity>(
                Colleague_PrefetchCredential( 
                    Credential_PrefetchCredentialSetting() ),
                Colleague_PrefetchCounterParty());
        }

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 18-Apr-2013 18:24:34   

Thanks for the contribution. I'm sure many would benefit from it.