Example #1
0
        private List <object> PhaseTwo(DataStoreMapping mapping, Type objectType, SelectStatementResult result, List <PreResult> toLoad)
        {
            List <object> objects        = new List <object>();
            int           keyColumnIndex = mapping.Table.Columns.IndexOf(GetKeyColumn(mapping));
            List <DataStoreMapping.Column> refColumns = mapping.RefColumns.ToList();

            foreach (var row in result.Rows)
            {
                var key = row.Values[keyColumnIndex];
                if (key == null)
                {
                    throw new DataException("Key cannot be null.");
                }
                var obj = objectMap.Get(objectType, key);
                if (obj == null)
                {
                    obj = mapping.Create();
                    objectMap.Add(objectType, key, obj);
                }
                objects.Add(obj);
                foreach (var member in refColumns)
                {
                    var alias         = "T";
                    var dbCriteria    = BuildByKeyCriteria(member.Type, row.Values[member.Index], alias);
                    var memberMapping = mappings[member.Type];
                    toLoad.Add(new PreResult()
                    {
                        Mapping    = memberMapping,
                        ObjectType = member.Type,
                        Statement  = PhaseOne(memberMapping, member.Type, dbCriteria, alias)
                    });
                }
            }
            return(objects);
        }
Example #2
0
 private void PhaseThree(DataStoreMapping mapping, List <object> objects, SelectStatementResult result)
 {
     for (int i = 0; i < objects.Count; i++)
     {
         mapping.Load(objects[i], result.Rows[i].Values, objectMap);
     }
 }
Example #3
0
        private SelectStatement PhaseOne(DataStoreMapping mapping, Type objectType, CriteriaOperator dbCriteria, string alias)
        {
            var statement = new SelectStatement(mapping.Table, alias);

            statement.Condition = dbCriteria;
            foreach (var column in mapping.Table.Columns)
            {
                statement.Operands.Add(new QueryOperand(column, alias));
            }
            return(statement);
        }
Example #4
0
 private DBColumn GetKeyColumn(DataStoreMapping mapping)
 {
     return(mapping.Table.Columns.First(c => c.IsKey));
 }
Example #5
0
        private void SetupInsertUpdateStatement(ModificationStatement statement, object obj, DataStoreMapping mapping)
        {
            var values = new object[mapping.Table.Columns.Count];

            mapping.Save(obj, values);
            for (int i = 0; i < values.Length; i++)
            {
                var column = mapping.Table.Columns[i];
                if (!column.IsIdentity)
                {
                    statement.Operands.Add(new QueryOperand(column, null));
                    statement.Parameters.Add(new OperandValue(values[i]));
                }
            }
        }
Example #6
0
 private void SetupUpdateDeleteStatement(ModificationStatement statement, object obj, DataStoreMapping mapping, string alias)
 {
     statement.Condition = new BinaryOperator(
         new QueryOperand(GetKeyColumn(mapping), alias),
         new OperandValue(mapping.GetKey(obj)),
         BinaryOperatorType.Equal);
 }