/// <summary> /// Constructor. /// </summary> protected WorkUnit(EntityType entityType, object entity, EntityField[] fields, object[] values) { if (entityType == null) { throw new ArgumentNullException("entityType"); } if (entity == null) { throw new ArgumentNullException("entity"); } if (fields == null) { throw new ArgumentNullException("fields"); } if (values == null) { throw new ArgumentNullException("values"); } // check... if (fields.Length != values.Length) { throw ExceptionHelper.CreateLengthMismatchException("fields", "values", fields.Length, values.Length); } // check... entityType.AssertIsOfType(entity); // set... _entityType = entityType; _entity = entity; _fields = fields; _values = values; }
/// <summary> /// Asserts that we can support the provided entity. /// </summary> /// <param name="entity"></param> private void AssertEntity(object entity) { if (entity == null) { throw new ArgumentNullException("entity"); } if (EntityType == null) { throw new ArgumentNullException("EntityType"); } EntityType.AssertIsOfType(entity); }
public static bool CompareEntityKeyValues(object entity1, object entity2) { if(entity1 == null) throw new ArgumentNullException("entity1"); if(entity2 == null) throw new ArgumentNullException("entity2"); // get... EntityType et = EntityType.GetEntityType(entity1, OnNotFound.ThrowException); if(et == null) throw new InvalidOperationException("et is null."); et.AssertIsOfType(entity2); // get... object[] key1 = et.Storage.GetKeyValues(entity1); if(key1 == null) throw new ArgumentNullException("key1"); object[] key2 = et.Storage.GetKeyValues(entity2); if(key2 == null) throw new ArgumentNullException("key2"); // compare... return CompareKeys(key1, key2); }
public override void DemandLoad(object entity, EntityField[] fields) { if (entity == null) { throw new ArgumentNullException("entity"); } if (fields == null) { throw new ArgumentNullException("fields"); } if (fields.Length == 0) { throw ExceptionHelper.CreateZeroLengthArgumentException("fields"); } // check... if (EntityType == null) { throw new ArgumentNullException("EntityType"); } EntityType.AssertIsOfType(entity); // new? if (this.Storage.IsNew(entity) == true) { throw new InvalidOperationException("Entity is new."); } if (this.Storage.IsDeleted(entity, false) == true) { throw new InvalidOperationException("Entity has been physically deleted."); } // create a filter... object[] keyValues = this.Storage.GetKeyValues(entity); SqlFilter filter = SqlFilter.CreateGetByIdFilter(this.EntityType, keyValues); // jm - 14-07-2006 - Hacked - Matt to sort out if (filter == null) { throw new InvalidOperationException("filter is null."); } filter.IgnorePartitioning = true; // clear the fields... filter.Fields.Clear(); filter.Fields.AddRange(fields); // get values... object[] values = filter.ExecuteValues(); if (values == null) { throw new ArgumentNullException("values"); } // check... if (values.Length != fields.Length) { throw ExceptionHelper.CreateLengthMismatchException("values", "fields", values.Length, fields.Length); } // init and set... this.Storage.BeginInitialize(entity); try { for (int index = 0; index < fields.Length; index++) { // value... EntityField field = fields[index]; if (field == null) { throw new InvalidOperationException("field is null."); } object value = values[index]; // encrypted? //if(field.IsEncrypted) //{ // if(value == null) // value = new EncryptedValue(null, (byte[])null); // else if(value is DBNull) // value = new EncryptedValue(typeof(DBNull), (byte[])null); // else // { // // switch... // switch(field.DBType) // { // case DbType.String: // case DbType.StringFixedLength: // case DbType.AnsiString: // case DbType.AnsiStringFixedLength: // value = new EncryptedValue(field.Type, (string)value); // break; // default: // throw new NotSupportedException(string.Format("Cannot handle '{0}' ({1}).", field.DBType, field.DBType.GetType())); // } // } //} if ((field.DBType == DbType.AnsiStringFixedLength || field.DBType == DbType.StringFixedLength) && value is string) { value = ((string)value).TrimEnd(); } // set... this.Storage.SetValue(entity, field, value, SetValueReason.DemandLoad); } } finally { this.Storage.EndInitialize(entity); } }