コード例 #1
0
        /// <summary>
        /// Obtains a data-contract instance representing the specified change-set, suitable for
        /// transmission and/or serialization to an audit log.
        /// </summary>
        /// <param name="operationName"></param>
        /// <param name="changeSet"></param>
        /// <returns></returns>
        public static ChangeSetData WriteChangeSet(string operationName, IEnumerable <EntityChange> changeSet)
        {
            var actionData = from entityChange in changeSet
                             select new ActionData
            {
                Type              = entityChange.ChangeType.ToString(),
                Class             = EntityRefUtils.GetClass(entityChange.EntityRef).FullName,
                OID               = EntityRefUtils.GetOID(entityChange.EntityRef).ToString(),
                Version           = EntityRefUtils.GetVersion(entityChange.EntityRef),
                ChangedProperties = WriteProperties(entityChange)
            };

            return(new ChangeSetData {
                Operation = StringUtilities.EmptyIfNull(operationName), Actions = actionData.ToList()
            });
        }
コード例 #2
0
        /// <summary>
        /// Loads the specified entity into this context.
        /// </summary>
        public Entity Load(EntityRef entityRef, EntityLoadFlags flags)
        {
            try
            {
                // use a proxy if EntityLoadFlags.Proxy is specified and EntityLoadFlags.CheckVersion is not specified (CheckVersion overrides Proxy)
                var useProxy = (flags & EntityLoadFlags.CheckVersion) == 0 && (flags & EntityLoadFlags.Proxy) == EntityLoadFlags.Proxy;
                var entity   = (Entity)Load(EntityRefUtils.GetClass(entityRef), EntityRefUtils.GetOID(entityRef), useProxy);

                // check version if necessary
                if ((flags & EntityLoadFlags.CheckVersion) == EntityLoadFlags.CheckVersion && !EntityRefUtils.GetVersion(entityRef).Equals(entity.Version))
                {
                    throw new EntityVersionException(EntityRefUtils.GetOID(entityRef), null);
                }

                return(entity);
            }
            catch (ObjectNotFoundException hibernateException)
            {
                // note that we will only get here if useProxy == false in the above block
                // if the entity is proxied, verification of its existence is deferred until the proxy is realized
                throw new EntityNotFoundException(hibernateException);
            }
        }