Esempio n. 1
0
 internal MaterializerEnumerator(DbDataReader reader, ExtensibleObjectContextBase context, bool skipDeletedItems)
 {
     this._reader           = reader;
     this._context          = context;
     this._skipDeletedItems = skipDeletedItems;
     this._current          = default(T);
 }
Esempio n. 2
0
        internal EntityQuery(ExtensibleObjectContextBase context, string queryClause)
        {
            Type entityType = typeof(ExtensibleEntity);

            //if (!entityType.IsAssignableFrom(typeof(T)))
            //  throw new ArgumentException("Must use a type inherited from ExtensibleEntity", "type");
            this._queryClause = queryClause;
            this._context     = context;
        }
Esempio n. 3
0
                public void Dispose()
                {
                    DbDataReader readerTmp = this._reader;

                    this._reader  = null;
                    this._context = null;
                    this._current = null;
                    if (readerTmp != null)
                    {
                        readerTmp.Dispose();
                    }
                }
Esempio n. 4
0
 internal static IEnumerable <T> CreateObjects <T>(DbDataReader reader, ExtensibleObjectContextBase context, bool skipDeletedItems)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (reader.IsClosed)
     {
         throw new InvalidOperationException("The data reader is closed");
     }
     return(new MaterializerEnumerable <T>(reader, context, skipDeletedItems));
 }
Esempio n. 5
0
                bool IEnumerator.MoveNext()
                {
                    IExtensibleEntity deletedEntity;

                    if (_context == null)
                    {
                        return(false);
                    }
                    do
                    {
                        _current = null;
                        if (!this._reader.Read())
                        {
                            _context = null;
                            return(false);
                        }
                        this._current = EntityMaterializer.CreateObject(typeof(T), _reader, _context, _skipDeletedItems, out deletedEntity);
                    }while (deletedEntity != null && _skipDeletedItems);
                    return(true);
                }
Esempio n. 6
0
 internal static IEnumerable <T> CreateObjects <T>(DbDataReader reader, ExtensibleObjectContextBase context)
 {
     return(CreateObjects <T>(reader, context, true));
 }
Esempio n. 7
0
        private static IExtensibleEntity CreateEntity(Type entityType, IDataRecord dbReader, ExtensibleObjectContextBase context, bool withExtensionValues)
        {
            ExtensibleEntity entity         = Activator.CreateInstance(entityType) as ExtensibleEntity;
            EntityMetadata   entityMetaData = ExtensibleEntity.GetEntityMetadata(entityType);

            FieldMetadata[] fields = withExtensionValues?entityMetaData.Fields:entityMetaData.PreDefinedFields;
            for (int i = 0; i < fields.Length; i++)
            {
                object value = dbReader[fields[i].Name]; //note: use .Name rather than .ColumnName
                if (value is DBNull)
                {
                    value = null;
                }
                entity.SetValueWithFlag(fields[i].Name, value, true); //don't set the dirty flag
            }
            return(entity);
        }
Esempio n. 8
0
        private static IExtensibleEntity CreateObject(Type entityType, DbDataReader record, ExtensibleObjectContextBase context, bool updatableFromCache, bool skipDeletedItems, out IExtensibleEntity deletedEntity)
        {
            IExtensibleEntity returnEntity = null;

            deletedEntity = null;
            EntityKey        key   = CreateEntityKey(entityType, record);
            EntityCacheEntry entry = context.Cache.FindCacheEntry(key);

            if (entry != null)
            {
                returnEntity = entry.Entity;
                switch (entry.State)
                {
                case EntityRowState.Added:
                    throw new InvalidOperationException("Added entity already exists in the cache");

                case EntityRowState.Deleted:
                    deletedEntity = entry.Entity;
                    break;
                }
                if (deletedEntity != null && skipDeletedItems)
                {
                    return(null);
                }
                else
                {
                    return(returnEntity); //return the entity from the cache
                }
            }

            returnEntity = CreateEntity(entityType, record, context, true); //create entity from db record
            context.Cache.AddEntry(returnEntity, false);
            return(returnEntity);
        }
Esempio n. 9
0
 internal static object CreateObject(Type entityType, DbDataReader record, ExtensibleObjectContextBase context, bool skipDeletedItems, out IExtensibleEntity deletedEntity)
 {
     return(CreateObject(entityType, record, context, false, skipDeletedItems, out deletedEntity));
 }
Esempio n. 10
0
 internal EntityQuery(ExtensibleObjectContextBase context, params KeyValuePair <string, object>[] conditions)
     : this(context, ToSqlClause(conditions))
 {
 }