Beispiel #1
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);
        }