当前位置: 首页>>代码示例>>C#>>正文


C# IEntity.ToObjectArray方法代码示例

本文整理汇总了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;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:42,代码来源:EntityModelBase.cs


注:本文中的IEntity.ToObjectArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。