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); }
//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); }
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); }