public override object LoadData(DataContext context, IDataReader datareader, object state)
        {
            object     item       = Activator.CreateInstance(ObjectType);
            QueryState queryState = state as QueryState;

            foreach (DataFieldMapping field in this._fieldList)
            {
                if (queryState == null)
                {
                    object obj   = datareader[field.Name];
                    object value = field.ToProperty(obj);
                    if (!Object.Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                    }
                }
                else if (queryState.CheckSelectField(field.Name))
                {
                    object obj   = datareader[field.Name];
                    object value = field.ToProperty(obj);
                    if (!Object.Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                    }
                }
            }
            return(item);
        }
        public override object LoadData(DataContext context, IDataReader datareader, object state)
        {
            QueryState queryState = state as QueryState;

            object [] objects = new object [mappings.Length];
            for (int i = 0; i < mappings.Length; i++)
            {
                string aliasName = aliasNames [i];
                objects [i] = mappings [i].LoadAliasJoinTableData(context, datareader, queryState, aliasName);
            }
            return(objects);
        }
Beispiel #3
0
        public override object LoadAliasJoinTableData(DataContext context, IDataReader dataReader,
                                                      QueryState queryState, string aliasName)
        {
            var data = base.LoadAliasJoinTableData(context, dataReader, queryState, aliasName);

            if (IsDataTableEntity)
            {
                UpdateDateTableEntity(data);
            }

            return(data);
        }
Beispiel #4
0
        public override object LoadData(DataContext context, IDataReader datareader, object state)
        {
            QueryState queryState = state as QueryState;
            object     value      = null;

            if (queryState == null)
            {
                value = dataDefine.LoadData(context, datareader, name, state);
            }
            else if (queryState.CheckSelectField(name))
            {
                value = dataDefine.LoadData(context, datareader, name, state);
            }
            return(value);
        }
Beispiel #5
0
        public override object LoadData(DataContext context, IDataReader datareader, object state)
        {
            QueryState queryState = state as QueryState;

            if (this._singleRelationFields.Count > 0)
            {
                queryState.InitialJoinData();
                return(LoadJoinTableData(context, datareader, queryState, string.Empty));
            }
            object item = Activator.CreateInstance(ObjectType);

            foreach (DataFieldMapping field in this._fieldList)
            {
                if (queryState == null)
                {
                    object obj   = datareader[field.Name];
                    object value = field.ToProperty(obj);
                    if (!Object.Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                    }
                }
                else if (queryState.CheckSelectField(field.Name))
                {
                    object obj   = datareader[field.Name];
                    object value = field.ToProperty(obj);
                    if (!Object.Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                    }
                }
            }
            if (_collectionRelationFields.Count > 0)
            {
                foreach (CollectionRelationFieldMapping mapping in _collectionRelationFields)
                {
                    mapping.Handler.Set(item, mapping.ToProperty(context, item, true));
                }
            }
            if (_isDataEntity)
            {
                DataEntity entity = item as DataEntity;
                entity.SetContext(context);
            }
            return(item);
        }
Beispiel #6
0
        public virtual QueryCommand QueryDynamicAggregate(DataContext context, AggregateModel model, QueryExpression query, QueryExpression having, OrderExpression order, Region region)
        {
            CreateSqlState    state       = new CreateSqlState(context);
            AggregateSelector selector    = model.GetSelector();
            AggregateGroupBy  groupBy     = model.GetGroupBy();
            CommandData       commandData = _factory.CreateAggregateTableCommand(model.EntityMapping, selector, groupBy, query, having, order, region, state);
            DbCommand         command     = commandData.CreateCommand(this, state);
            QueryState        queryState  = new QueryState();

            queryState.SetSelector(selector);
            QueryCommand queryCommand = new QueryCommand()
            {
                Command   = command,
                InnerPage = commandData.InnerPage,
                State     = queryState
            };

            return(queryCommand);
        }
 public object ToProperty(DataContext context, IDataReader datareader, QueryState queryState, string fieldPath)
 {
     if (!queryState.GetJoinData(fieldPath, out object value))
     {
         string aliasName = queryState.GetAliasName(fieldPath);
         foreach (DataFieldInfo info in this.relateInfos)
         {
             string name = string.Format("{0}_{1}", aliasName, info.FieldName);
             if (queryState.CheckSelectField(aliasName))
             {
                 object obj = datareader[name];
                 if (Object.Equals(obj, DBNull.Value) || Object.Equals(obj, null))
                 {
                     queryState.SetJoinData(fieldPath, null);
                     return(null);
                 }
             }
             else
             {
                 queryState.SetJoinData(fieldPath, null);
                 return(null);
             }
         }
         if (queryState.CheckSelectField(aliasName))
         {
             //object item = Activator.CreateInstance(this.RelateMapping.ObjectType);
             //queryState.SetJoinData(fieldPath, item);
             //this.relateEntityMapping.LoadJoinTableData(context, datareader, item, queryState, fieldPath);
             //value = item;
             value = this.relateEntityMapping.LoadJoinTableData(context, datareader, queryState, fieldPath);
         }
         else
         {
             queryState.SetJoinData(fieldPath, null);
             return(null);
         }
     }
     return(value);
 }
Beispiel #8
0
        public virtual QueryCommand QueryJoinData(DataContext context, DataMapping mapping, ISelector selector, List <IJoinModel> models, QueryExpression query, OrderExpression order, bool distinct, Region region)
        {
            CreateSqlState state       = new CreateSqlState(context);
            CommandData    commandData = _factory.CreateSelectJoinTableCommand(selector, models, query, order, distinct, region, state);
            DbCommand      command     = commandData.CreateCommand(this, state);
            QueryState     queryState  = new QueryState();

            foreach (IJoinModel model in models)
            {
                if (model.NoDataSetEntityNull)
                {
                    queryState.SetNoDataSetNull(model.AliasTableName);
                }
            }
            queryState.SetSelector(selector);
            QueryCommand queryCommand = new QueryCommand()
            {
                Command   = command,
                InnerPage = commandData.InnerPage,
                State     = queryState
            };

            return(queryCommand);
        }
Beispiel #9
0
        public virtual QueryCommand QueryEntityData(DataContext context, DataEntityMapping mapping, ISelector selector, QueryExpression query, OrderExpression order, bool distinct, Region region)
        {
            RelationMap relationMap = mapping.GetRelationMap();

            if (selector == null)
            {
                selector = relationMap.GetDefaultSelector();
            }
            CreateSqlState state       = new CreateSqlState(context);
            CommandData    commandData = _factory.CreateSelectDataCommand(mapping, relationMap, selector, query, order, distinct, region, state);
            DbCommand      command     = commandData.CreateCommand(this, state);
            QueryState     queryState  = new QueryState();

            queryState.SetRelationMap(relationMap);
            queryState.SetSelector(selector);
            QueryCommand queryCommand = new QueryCommand()
            {
                Command   = command,
                InnerPage = commandData.InnerPage,
                State     = queryState
            };

            return(queryCommand);
        }
Beispiel #10
0
        public virtual object LoadJoinTableData(DataContext context, IDataReader dataReader, QueryState queryState,
                                                string fieldPath)
        {
            var item = Activator.CreateInstance(ObjectType);

            queryState.SetJoinData(fieldPath, item);
            var aliasName = queryState.GetAliasName(fieldPath);

            foreach (var field in _fieldList)
            {
                var name = $"{aliasName}_{field.Name}";
                if (queryState.CheckSelectField(name))
                {
                    var obj   = dataReader[name];
                    var value = field.ToProperty(obj);
                    if (!Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                    }
                }
            }

            if (_collectionRelationFields.Count > 0)
            {
                foreach (var mapping in _collectionRelationFields)
                {
                    mapping.Handler.Set(item, mapping.ToProperty(context, item, true));
                }
            }

            foreach (var mapping in _singleRelationFields)
            {
                var path  = $"{fieldPath}.{mapping.FieldName}";
                var value = mapping.ToProperty(context, dataReader, queryState, path);
                if (!Equals(value, null))
                {
                    mapping.Handler.Set(item, value);
                }
            }

            if (IsDataEntity && item is DataEntity entity)
            {
                entity.SetContext(context);
            }

            return(item);
        }
Beispiel #11
0
 public object LoadAliasJoinTableData(DataContext context, IDataReader dataReader, QueryState queryState, string aliasName)
 {
     // object value = null;
     // if (queryState == null) {
     //     value = dataDefine.LoadData(context, dataReader, Name, null);
     // } else if (queryState.CheckSelectField(Name)) {
     //     value = dataDefine.LoadData(context, dataReader, Name, queryState);
     // }
     // return value;
     return(dataDefine.LoadData(context, dataReader, queryState));
 }
Beispiel #12
0
 public abstract object LoadAliasJoinTableData(DataContext context, IDataReader datareader, QueryState queryState, string aliasName);
Beispiel #13
0
        public override object LoadAliasJoinTableData(DataContext context, IDataReader datareader, QueryState queryState, string aliasName)
        {
            object[] args          = new object[this._fieldList.Count];
            int      index         = 0;
            bool     nodataSetNull = queryState != null?queryState.CheckNoDataSetNull(aliasName) : false;

            bool hasData = false;

            foreach (DynamicFieldMapping field in this._fieldList)
            {
                string name = string.Format("{0}_{1}", aliasName, field.Name);
                if (queryState == null)
                {
                    object obj   = datareader[name];
                    object value = field.ToProperty(obj);
                    args[index] = value;
                }
                else if (queryState.CheckSelectField(name))
                {
                    object obj   = datareader[name];
                    object value = field.ToProperty(obj);
                    if (!Object.Equals(value, null))
                    {
                        hasData = true;
                    }
                    args[index] = value;
                }
                index++;
            }
            if (!hasData && nodataSetNull)
            {
                return(null);
            }
            object item = Activator.CreateInstance(ObjectType, args);

            return(item);
        }
Beispiel #14
0
        public virtual object LoadAliasJoinTableData(DataContext context, IDataReader dataReader, QueryState queryState,
                                                     string aliasName)
        {
            var item          = Activator.CreateInstance(ObjectType);
            var nodataSetNull = queryState?.CheckNoDataSetNull(aliasName) ?? false;
            var hasData       = false;

            foreach (var field in _fieldList)
            {
                if (field == null)
                {
                    continue;
                }
                var name = $"{aliasName}_{field.Name}";
                if (queryState == null)
                {
                    var obj   = dataReader[name];
                    var value = field.ToProperty(obj);
                    if (!Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                    }
                }
                else if (queryState.CheckSelectField(name))
                {
                    var obj   = dataReader[name];
                    var value = field.ToProperty(obj);
                    if (!Equals(value, null))
                    {
                        hasData = true;
                        field.Handler.Set(item, value);
                    }
                }
            }

            if (_collectionRelationFields.Count > 0)
            {
                foreach (var mapping in _collectionRelationFields)
                {
                    mapping.Handler.Set(item, mapping.ToProperty(context, item, false));
                }
            }

            if (!hasData && nodataSetNull)
            {
                return(null);
            }

            if (IsDataEntity && item is DataEntity entity)
            {
                entity.SetContext(context);
            }

            return(item);
        }
Beispiel #15
0
        //public virtual void LoadJoinTableData(DataContext context, IDataReader datareader, object item, QueryState queryState, string fieldPath)
        //{
        //    string aliasName = queryState.GetAliasName(fieldPath);
        //    foreach (DataFieldMapping field in this._fieldList) {
        //        string name = string.Format("{0}_{1}", aliasName, field.Name);
        //        if (queryState.CheckSelectField(name)) {
        //            object obj = datareader[name];
        //            object value = field.ToProperty(obj);
        //            if (!Object.Equals(value, null)) {
        //                field.Handler.Set(item, value);
        //            }
        //        }
        //    }
        //    if (_collectionRelationFields.Count > 0) {
        //        foreach (CollectionRelationFieldMapping mapping in _collectionRelationFields) {
        //            mapping.Handler.Set(item, mapping.ToProperty(context, item, true));
        //        }
        //    }

        //    foreach (SingleRelationFieldMapping mapping in _singleRelationFields) {
        //        string fpath = string.Format("{0}.{1}", fieldPath, mapping.FieldName);
        //        object value = mapping.ToProperty(context, datareader, queryState, fpath);
        //        if (!Object.Equals(value, null)) {
        //            mapping.Handler.Set(item, value);
        //        }
        //    }
        //    if (item is DataEntity entity) {
        //        entity.SetContext(context);
        //        entity.LoadDataComplete();
        //    }
        //}

        public virtual object LoadJoinTableData(DataContext context, IDataReader datareader, QueryState queryState, string fieldPath)
        {
            object item = Activator.CreateInstance(this.ObjectType);

            queryState.SetJoinData(fieldPath, item);
            string aliasName = queryState.GetAliasName(fieldPath);

            foreach (DataFieldMapping field in this._fieldList)
            {
                string name = string.Format("{0}_{1}", aliasName, field.Name);
                if (queryState.CheckSelectField(name))
                {
                    object obj   = datareader[name];
                    object value = field.ToProperty(obj);
                    if (!Object.Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                    }
                }
            }
            if (_collectionRelationFields.Count > 0)
            {
                foreach (CollectionRelationFieldMapping mapping in _collectionRelationFields)
                {
                    mapping.Handler.Set(item, mapping.ToProperty(context, item, true));
                }
            }

            foreach (SingleRelationFieldMapping mapping in _singleRelationFields)
            {
                string fpath = string.Format("{0}.{1}", fieldPath, mapping.FieldName);
                object value = mapping.ToProperty(context, datareader, queryState, fpath);
                if (!Object.Equals(value, null))
                {
                    mapping.Handler.Set(item, value);
                }
            }
            if (_isDataEntity)
            {
                DataEntity entity = item as DataEntity;
                entity.SetContext(context);
            }
            return(item);
        }
Beispiel #16
0
        public object LoadAliasJoinTableData(DataContext context, IDataReader datareader, QueryState queryState, string aliasName)
        {
            string fieldname = string.Format("{0}_{1}", aliasName, name);
            object value     = null;

            if (queryState == null)
            {
                value = dataDefine.LoadData(context, datareader, name, queryState);
            }
            else if (queryState.CheckSelectField(name))
            {
                value = dataDefine.LoadData(context, datareader, name, queryState);
            }
            return(value);
        }
        public override object LoadAliasJoinTableData(DataContext context, IDataReader datareader, QueryState queryState, string aliasName)
        {
            object item          = Activator.CreateInstance(ObjectType);
            bool   nodataSetNull = queryState != null?queryState.CheckNoDataSetNull(aliasName) : false;

            bool hasData = false;

            foreach (DataFieldMapping field in this._fieldList)
            {
                string name = string.Format("{0}_{1}", aliasName, field.Name);
                if (queryState == null)
                {
                    object obj   = datareader [name];
                    object value = field.ToProperty(obj);
                    if (!Object.Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                    }
                }
                else if (queryState.CheckSelectField(name))
                {
                    object obj   = datareader [name];
                    object value = field.ToProperty(obj);
                    if (!Object.Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                        hasData = true;
                    }
                }
            }
            if (!hasData && nodataSetNull)
            {
                return(null);
            }
            return(item);
        }
        public override object LoadAliasJoinTableData(DataContext context, IDataReader dataReader, QueryState queryState, string aliasName)
        {
            var item          = Activator.CreateInstance(ObjectType);
            var nodataSetNull = queryState?.CheckNoDataSetNull(aliasName) ?? false;
            var hasData       = false;

            foreach (var field in _fieldList)
            {
                var name = string.Format("{0}_{1}", aliasName, field.Name);
                if (queryState == null)
                {
                    var obj   = dataReader [name];
                    var value = field.ToProperty(obj);
                    if (!Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                    }
                }
                else if (queryState.CheckSelectField(name))
                {
                    var obj   = dataReader [name];
                    var value = field.ToProperty(obj);
                    if (!Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                        hasData = true;
                    }
                }
            }
            if (!hasData && nodataSetNull)
            {
                return(null);
            }
            return(item);
        }
Beispiel #19
0
        public override object LoadJoinTableData(DataContext context, IDataReader datareader, QueryState queryState, string fieldPath)
        {
            object data = base.LoadJoinTableData(context, datareader, queryState, fieldPath);

            if (_isDataTableEntity)
            {
                UpdateDateTableEntity(data);
            }
            return(data);
        }
Beispiel #20
0
        public virtual object LoadAliasJoinTableData(DataContext context, IDataReader datareader, QueryState queryState, string aliasName)
        {
            object item          = Activator.CreateInstance(ObjectType);
            bool   nodataSetNull = queryState != null?queryState.CheckNoDataSetNull(aliasName) : false;

            bool hasData = false;

            foreach (DataFieldMapping field in this._fieldList)
            {
                if (field == null)
                {
                    continue;
                }
                string name = string.Format("{0}_{1}", aliasName, field.Name);
                if (queryState == null)
                {
                    object obj   = datareader[name];
                    object value = field.ToProperty(obj);
                    if (!Object.Equals(value, null))
                    {
                        field.Handler.Set(item, value);
                    }
                }
                else if (queryState.CheckSelectField(name))
                {
                    object obj   = datareader[name];
                    object value = field.ToProperty(obj);
                    if (!Object.Equals(value, null))
                    {
                        hasData = true;
                        field.Handler.Set(item, value);
                    }
                }
            }
            if (_collectionRelationFields.Count > 0)
            {
                foreach (CollectionRelationFieldMapping mapping in _collectionRelationFields)
                {
                    mapping.Handler.Set(item, mapping.ToProperty(context, item, false));
                }
            }
            if (!hasData && nodataSetNull)
            {
                return(null);
            }
            if (_isDataEntity)
            {
                DataEntity entity = item as DataEntity;
                entity.SetContext(context);
            }
            return(item);
        }