Exemplo n.º 1
0
        public virtual void Add(IntermediateEntity intermediateEntity)
        {
            var intermediateType = intermediateEntity.GetType();

            if (!trackedIntermediateEntities.ContainsKey(intermediateType))
            {
                trackedIntermediateEntities.Add(intermediateType, new List <IntermediateEntity>());
            }

            trackedIntermediateEntities[intermediateType].Add(intermediateEntity);
        }
Exemplo n.º 2
0
        public IEntity GetOrCreateEntity(object[] sources)
        {
            if (sources == null || sources.Count() == 0)
            {
                return(null);
            }

            //sources represent the full inheritance hierarchy required to create the instance.
            //eg: Lawyer will have instanced of the table entities: lawyer, professional, user.

            IntermediateEntity intermediateEntity = null;
            var last = sources.Length - 1;

            for (int i = last; i >= 0; i--)
            {
                ITableEntity src = sources[i] as ITableEntity;

                if (src._getIntermediateEntity() == null)
                {
                    intermediateEntity = i == last?Activator.CreateInstance(classMappings[i].IntermediateEntityType, new object[] { sources[i] }) as IntermediateEntity
                                         : Activator.CreateInstance(classMappings[i].IntermediateEntityType, new object[] { sources[i], intermediateEntity }) as IntermediateEntity;

                    entityContext.AttachContext(intermediateEntity);

                    src._setIntermediateEntity(intermediateEntity);
                }
                else
                {
                    intermediateEntity = src._getIntermediateEntity();
                }
            }

            //See if the type has a TypeFactory. If so, it decides which Type to instantiate.
            IEntity entity = Activator.CreateInstance(classMappings[0].EntityType, new object[] { intermediateEntity }) as IEntity;

            //If there is a type factory, allow the typefactory to suggest the type to create (or recreate).
            var typeFactory = entityContext._InternalServices.TypeTranslationUtil.GetTypeFactory(entityType);

            if (typeFactory != null)
            {
                var typeToConstruct = typeFactory.GetTypeOf(entity);
                if (typeToConstruct != null)
                {
                    entity = Activator.CreateInstance(typeToConstruct) as IEntity;
                    MethodFinder.IEntity._setIntermediateEntity(typeToConstruct).Invoke(entity, new object[] { intermediateEntity });
                }
            }

            return(entity);
        }
        public static void ShareEntityContext(this IIntermediateEntityContainer container, IntermediateEntity entity)
        {
            //You can't share context with a null, right?
            if (entity != null)
            {
                var parent = container.GetParent();

                if (entity.EntityContext != null && parent.EntityContext == null)
                {
                    entity.EntityContext.AttachContext(parent);
                }
                else if (parent.EntityContext != null && entity.EntityContext == null)
                {
                    parent.EntityContext.AttachContext(entity);
                }
            }
        }
Exemplo n.º 4
0
 public void _setIntermediateEntity(IntermediateEntity intermediateEntity)
 {
     _intermediateEntity = intermediateEntity as intermediateNS.Project;
 }
Exemplo n.º 5
0
 public void _setIntermediateEntity(IntermediateEntity intermediateEntity)
 {
     _intermediateEntity = intermediateEntity as intermediateNS.Company;
 }
Exemplo n.º 6
0
 public void _setIntermediateEntity(IntermediateEntity intermediateEntity)
 {
     _intermediateEntity = intermediateEntity as intermediateNS.User;
 }
Exemplo n.º 7
0
 public void _setIntermediateEntity(IntermediateEntity intermediateEntity)
 {
     _intermediateEntity = intermediateEntity as intermediateNS.Account;
 }
Exemplo n.º 8
0
 public void _setIntermediateEntity(IntermediateEntity intermediateEntity)
 {
     _intermediateEntity = intermediateEntity as intermediateNS.PortfolioEntry;
 }
Exemplo n.º 9
0
 public static TEntity GetEntity <TEntity, TTableEntity>(this IntermediateEntity <TEntity, TTableEntity> intermediateEntity)
     where TEntity : class, IEntity
     where TTableEntity : ITableEntity
 {
     return((null == intermediateEntity) ? (TEntity)null : intermediateEntity._entity);
 }