Пример #1
0
        public T ExecuteQuery <T>(
            IExecutionPlan <T> plan,
            IExecutionContext context)
        {
            ITable[] tables = TableLocator.FindAffectedTables(context.Database, plan);

            for (int i = 0; i < tables.Length; i++)
            {
                this.AcquireReadLock(tables[i], context);
            }

            try
            {
                var item = plan.Execute(context);

                EntityPropertyCloner <T> cloner = null;
                if (this.database.Tables.IsEntityType <T>())
                {
                    cloner = EntityPropertyCloner <T> .Instance;
                }
                if (cloner != null && item != null)
                {
                    var cloned = Activator.CreateInstance <T>();
                    cloner.Clone(item, cloned);

                    // Remove Aliased Attributes these are getting added by the Query Plan Execution
#pragma warning disable IDE0019 // Use pattern matching
                    var entity = item as Entity;
#pragma warning restore IDE0019 // Use pattern matching
                    if (entity != null)
                    {
                        foreach (var attribute in entity.Attributes.ToList().Where(attribute => attribute.Value is AliasedValue))
                        {
                            entity.Attributes.Remove(attribute.Key);
                        }
                    }

                    return(cloned);
                }
                else
                {
                    return(item);
                }
            }
            finally
            {
                for (int i = 0; i < tables.Length; i++)
                {
                    this.ReleaseReadLock(tables[i], context);
                }
            }
        }
Пример #2
0
        private IEnumerator <T> ExecuteQuery <T>(
            IExecutionPlan <IEnumerable <T> > plan,
            IExecutionContext context,
            ITable[] tablesToLock,
            bool cloneEntities)
        {
            ITable[] tables = TableLocator.FindAffectedTables(context.Database, plan);

            EntityPropertyCloner <T> cloner = null;

            if (cloneEntities && this.database.Tables.IsEntityType <T>())
            {
                cloner = EntityPropertyCloner <T> .Instance;
            }

            LinkedList <T> result = new LinkedList <T>();

            for (int i = 0; i < tablesToLock.Length; i++)
            {
                this.AcquireReadLock(tablesToLock[i], context);
            }

            IEnumerable <T> query = plan.Execute(context);

            try
            {
                foreach (T item in query)
                {
                    if (cloner != null)
                    {
                        T resultEntity = Activator.CreateInstance <T>();
                        cloner.Clone(item, resultEntity);

                        result.AddLast(resultEntity);

                        // Remove Aliased Attributes these are getting added by the Query Plan Execution
#pragma warning disable IDE0019 // Use pattern matching
                        var entity = item as Entity;
#pragma warning restore IDE0019 // Use pattern matching
                        if (entity != null)
                        {
                            foreach (var attribute in entity.Attributes.ToList().Where(attribute => attribute.Value is AliasedValue))
                            {
                                entity.Attributes.Remove(attribute.Key);
                            }
                        }
                    }
                    else
                    {
                        result.AddLast(item);
                    }
                }
            }
            finally
            {
                for (int i = 0; i < tablesToLock.Length; i++)
                {
                    this.ReleaseReadLock(tablesToLock[i], context);
                }
            }

            return(result.GetEnumerator());
        }
 public static void WriteEntityUpdate <TEntity>(this ITransactionLog log, EntityPropertyCloner <TEntity> propertyCloner, TEntity storedEntity, TEntity oldEntity)
     where TEntity : class
 {
     log.Write(new UpdateEntityLogItem <TEntity>(propertyCloner, storedEntity, oldEntity));
 }
Пример #4
0
 public UpdateEntityLogItem(EntityPropertyCloner <TEntity> propertyCloner, TEntity storedEntity, TEntity oldEntity)
 {
     this.storedEntity   = storedEntity;
     this.oldEntity      = oldEntity;
     this.propertyCloner = propertyCloner;
 }