public EntityContext(string connectionStringName) { _helper = Xinchen.DbEntity.DbHelper.GetInstance(connectionStringName); _properties = this.GetType().GetProperties(); _entitySets = new Dictionary <Type, object>(); foreach (var property in _properties.Where(x => x.PropertyType.IsGenericType && x.PropertyType.FullName.StartsWith("Xinchen.DbEntity.EntitySet"))) { object entitySet = Activator.CreateInstance(property.PropertyType, connectionStringName); property.SetValue(this, entitySet, null); _entitySets.Add(property.PropertyType.GetGenericArguments()[0], entitySet); } }
public EntitySet(EntityContext context) { this._helper = Xinchen.DbEntity.DbHelper.GetInstance(context.DbHelper.ConnectionString); this._entityType = typeof(TEntity); this._entityMapper = new EntityMapper <TEntity>(); this._properties = this._entityMapper.Properties; this._propertyNames = new string[this._properties.Length]; this._propertyDict = new Dictionary <string, PropertyInfo>(); for (int i = 0; i < this._properties.Length; i++) { this._propertyNames[i] = "[" + this._properties[i].Name + "]"; this._propertyDict.Add(this._properties[i].Name, this._properties[i]); } this._tableAttr = (TableAttribute)this._entityType.GetCustomAttributes(EntitySet <TEntity> ._tableAttrType, true).FirstOrDefault <object>(); this._keyProperty = this._properties.FirstOrDefault <PropertyInfo>(propertyInfo => AttributeHelper.GetAttribute <KeyAttribute>(propertyInfo) != null); if (this._keyProperty == null) { throw new EntityException("实体没有主键:" + TypeName); } this._autoIncrementProperty = this._properties.FirstOrDefault <PropertyInfo>(x => AttributeHelper.GetAttribute <AutoIncrementAttribute>(x) != null); }