public EntityBase GetEntityById(Type type, object id) { if (id == null) { return(null); } ILoader loader = GetLoader(type); if (!ClassFactory.GetObjectDescription(type, this).IsAggregated) { EntityBase e = Caches.GetEntityById(loader.ReflectedType, id); if (e == null) { if (_loadAllOnGetById && !ClassFactory.GetObjectDescription(type, this).IsDenyGetAllOnGetById) { List <EntityBase> temp = GetEntities(type); e = Caches[loader.ReflectedType].Contains(id) ? Caches[loader.ReflectedType][id] : null; } else { e = loader.LoadEntityById(id); } } return(e); } else { AgregatedClassAttribute aggr = ClassFactory.GetObjectDescription(type, this).GetAttribute <AgregatedClassAttribute>(); List <EntityBase> l = new List <EntityBase>(); foreach (Type t in aggr.ChildTypes) { EntityBase e = GetEntityById(t, id); if (e != null) { return(e); } } return(null); } }
public void Add(T e) { List.Add(e); SetOwnerState(EntityState.Changed); if (_property != null && _property.IsOneToManyRelation) { ObjectDescription newObjectDescription = ClassFactory.GetObjectDescription(e.GetType(), _owner.CreatorPs); foreach (PropertyDescription pd in newObjectDescription.Relations) { if (!pd.IsOneToOneRelation || !pd.IsMapped) { continue; } if (pd.RelationAttribute.RelatedColumn == _property.ReflectedObject.IdField.Name && pd.RelatedType.IsAssignableFrom(_owner.GetType())) { pd.SetValue(e, _owner); break; } } } }
public Mapper(Type entityType, PersistentStorage ps) { _ps = ps; _entityType = entityType; _entityFieldsMapper = new EntityFieldsMapper(EntityType, _ps); TableAttribute attr = ClassFactory.GetObjectDescription(_entityType, ps).DbTableAttribute; if (attr == null) { _tableName = entityType.Name; } else { _tableName = attr.TableName; } DbSchemaAttribute attr2 = ClassFactory.GetObjectDescription(_entityType, ps).GetAttribute <DbSchemaAttribute>(); if (attr2 != null) { _schemaName = attr2.SchemaName; } }
internal object this [string key, bool oldValue] { get { return(GetValueInternal(key, oldValue, false)); } set { if (oldValue) { throw new Exception("You can not change the old value of the property"); } else { ObjectDescription d = ClassFactory.GetObjectDescription(GetType(), CreatorPs); //ClassFactory.GetThreadDefaultPs(System.Threading.Thread.CurrentThread)); //if ( State != EntityState.Unchanged ) //{ //State = EntityState.Changed; //SetValueToDic(_oldValues, key, value); //if ( PropertyValueChanged != null ) // PropertyValueChanged(this, d.Properties[key], _values[key,true], value); //} //SetValueToDic(_values, key, value); _values[key] = value; if (PropertyValueSet != null) { PropertyValueSet(this, d.Properties[key], value); } if (State != EntityState.New && State != EntityState.NewDeleted && State != EntityState.Deleted) { State = EntityState.Changed; } } } }