/// <summary>
        /// Creates new entity context mapper object.
        /// </summary>
        public EntityMapper(ObjectMappingType objectMappingType, IDataReader dataReader)
        {
            // Get entity context.
            var entityContext = EntityContext <TEntity> .GetEntityContext();

            // Get properties.
            m_Properties = entityContext.Properties.Values.Where(x => !x.IsForeignKey);

            // Set members.
            m_ObjectMappingType = objectMappingType;

            // Determine mapping sets.
            DetermineInterfaceSets(dataReader);
        }
Exemple #2
0
        /// <summary>
        /// Creates new object context mapper.
        /// </summary>
        public ObjectMapper(ObjectMappingType objectMappingType, IDataReader dataReader)
        {
            // Set members.
            m_ObjectMappingType = objectMappingType;

            // Get object context.
            var objectContext = ObjectContext <TObject> .GetObjectContext();

            // Get properties.
            m_Properties = objectContext.Properties.Values;

            // Determine mapping sets.
            DetermineInterfaceSets(dataReader);
        }
        /// <summary>
        /// Get collection by sql command.
        /// </summary>
        public static IEnumerable <TObject> GetByQueryCommand(DbCommand command, ObjectMappingType objectMappingType)
        {
            // Create instance of return collection
            var objectCollection = new List <TObject>();

            // Get ambient query context.
            var ambientContext = QueryContext.GetAmbientQueryContext();

            // Create connection to database from ambient query context.
            using (DbConnection connection = ambientContext.CreateConnection())
            {
                // Pass connection to command object.
                command.Connection = connection;

                // Open connection to database
                connection.Open();

                // Execute Sql data reader
                using (DbDataReader dataReader = command.ExecuteReader())
                {
                    // Create mapper.
                    var objectMapper = new ObjectMapper <TObject>(objectMappingType, dataReader);

                    // Read data.
                    while (dataReader.Read())
                    {
                        // Create new TEntity instance
                        var @object = new TObject();

                        // Map raw data to object.
                        objectMapper.MapToObject(@object, dataReader);

                        // Add entity to collection
                        objectCollection.Add(@object);
                    }
                }
            }

            // Return object collection.
            return(objectCollection);
        }