本文整理汇总了C#中IEntity.ToObjectArray方法的典型用法代码示例。如果您正苦于以下问题:C# IEntity.ToObjectArray方法的具体用法?C# IEntity.ToObjectArray怎么用?C# IEntity.ToObjectArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEntity
的用法示例。
在下文中一共展示了IEntity.ToObjectArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromExistingEntity
/// <summary>
/// Initializes entity members with all data stored in the given entity.
/// </summary>
/// <param name="existing">Instance of IEntity. Must be compatibile with current entity; otherwise an exception is generated.</param>
/// <remarks>Copies all class members. Parent entities are not copied by reference, but cloned (deep copy).</remarks>
protected virtual void FromExistingEntity(IEntity existing)
{
if (_Table == null)
_Table = existing.Table.Clone(null);
// throw new ArgumentException("Given entity doesn't belong to same table as current entity. Expected " + _Table.TableName + ", but " + existing.Table.TableName + " was provided.", "existing");
if (_Table.TableName != existing.Table.TableName)
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Messages.EntityModelBase_EntityNotFromSameTableExpextedXButGotY, _Table.TableName, existing.Table.TableName), "existing");
// Clone meta. 'this.table' will be instantiated when _Table getter is accessed for the first time.
this.tableAlias = existing.Table.Alias;
this.dbTableClass = existing.Table.GetType();
this.table = null;
// Members mapped to fields.
object[] entityValues = CloneObjectArray(existing.ToObjectArray());
FromObjectArray(entityValues);
// Parents. Temporary disable relation navigation to prevent possible data-access when cloning parents.
bool relationNavigationStatusBeforeParentCloning = existing.RelationshipNavigationEnabled;
existing.RelationshipNavigationEnabled = false;
foreach (DbRelation fk in _Table.ForeignKeys)
{
IEntity parent = existing.GetParent(fk);
// Only set if not null (it's already null) because when setting parent entity property to NULL
// then FK field would also nulled, thus undoing the previous step (field cloning) and causing error.
if (parent != null)
this.SetParent(fk, parent.Clone() as IEntity);
}
// Restore original status of relationship navigation.
existing.RelationshipNavigationEnabled = relationNavigationStatusBeforeParentCloning;
// Behavior. Entity state, relation navigation.
this.entityState = existing.EntityState;
this.relationshipNavigationEnabled = existing.RelationshipNavigationEnabled;
}