コード例 #1
0
        public void Update <TEntity>(TEntity entity)
            where TEntity : class
        {
            TEntity updated  = entity;
            TEntity original = GetAll <TEntity>().Single(item => EntityHelper.AreKeysEqual(entity, item));

            PendingActions.Add(() => EntityHelper.SetValueProperties(updated, original));
            UpdateAssociations(entity);
        }
コード例 #2
0
 public TEntity GetById <TEntity>(params object[] ids)
     where TEntity : class
 {
     return(GetAll <TEntity>().SingleOrDefault(ent => EntityHelper.AreKeysEqual(ent, ids)));
 }
コード例 #3
0
 private void UpdateAssociations <TEntity>(TEntity entity)
 {
     foreach (PropertyInfo associationProp in EntityHelper.AssociationPropertyMap[typeof(TEntity)])
     {
         IEnumerable values = (IEnumerable)associationProp.GetValue(entity);
         foreach (object value in values)
         {
             Type   objType  = value.GetType();
             object original = Committed.FirstOrDefault(obj => obj.GetType() == value.GetType() && EntityHelper.AreKeysEqual(obj, value));
             if (original == null)
             {
                 CreateMethod.MakeGenericMethod(objType).Invoke(this, new[] { value });
             }
             else
             {
                 UpdateMethod.MakeGenericMethod(objType).Invoke(this, new[] { value });
             }
         }
     }
 }