コード例 #1
0
        /// <summary>
        /// Generates a temporary ID for an <see cref="IEntity"/>.  The temporary ID will be mapped to a real ID when
        /// <see cref="SaveChanges"/> is called.
        /// <seealso cref="IIdGenerator"/>
        /// </summary>
        /// <param name="entity">The Entity object for which the new ID will be generated</param>
        /// <param name="entityProperty">The EntityProperty in which the new ID will be set </param>
        /// <remarks>
        /// You must implement the <see cref="IIdGenerator"/> interface to use ID generation.  See the
        /// <b>DevForce Developer's Guide</b> for more information on custom ID generation.
        /// <para>
        /// If you are using a SQL Server <b>Identity</b> property you do not need to call <b>GenerateId</b>
        /// for the property.
        /// </para>
        /// </remarks>
        /// <exception cref="ArgumentException">Incorrect entity type/property</exception>
        /// <exception cref="IdeaBladeException">IdGenerator not found</exception>
        public UniqueId GenerateId(IEntity entity, DataProperty entityProperty)
        {
            var aspect     = entity.EntityAspect;
            var entityType = entity.GetType();

            if (entityProperty.IsForeignKey)
            {
                String msg = String.Format(
                    "Cannot call GenerateId on '{0}.{1}'. GenerateId cannot be called on ForeignKey properties ( even if they are also part of a PrimaryKey).  Call GenerateId instead on the 'source' primary key.",
                    entityProperty.ParentType.Name, entityProperty.Name);
                throw new ArgumentException("entityProperty", msg);
            }
            if (!entityProperty.ParentType.ClrType.IsAssignableFrom(entityType))
            {
                String msg = String.Format("The EntityType '{0}' for Property '{1}' must be of EntityType '{2}' or one of its subtypes", entityProperty.ParentType, entityProperty.Name, entityType);
                throw new ArgumentException("entityProperty", msg);
            }
            // Associate this entity with this EntityManager if it previously wasn't
            // - so that it cannot later be used in another EntityManager
            if (aspect.EntityGroup == null)
            {
                aspect.EntityGroup = GetEntityGroup(entityType);
            }

            if (KeyGenerator == null)
            {
                throw new Exception("Unable to locate a KeyGenerator");
            }

            object nextTempId = KeyGenerator.GetNextTempId(entityProperty);

            aspect.SetDpValue(entityProperty, nextTempId);
            var aUniqueId = new UniqueId(entityProperty, nextTempId);

            // don't add to tempId's collection until the entity itself is added.
            if (aspect.EntityState != EntityState.Detached)
            {
                AddToTempIds(aUniqueId);
            }
            return(aUniqueId);
        }
コード例 #2
0
ファイル: EntityType.cs プロジェクト: novice3030/Breeze
        internal override DataProperty AddDataProperty(DataProperty dp)
        {
            base.AddDataProperty(dp);

            if (dp.IsPartOfKey)
            {
                _keyProperties.Add(dp);
            }

            if (dp.IsForeignKey)
            {
                _foreignKeyProperties.Add(dp);
            }

            if (dp.IsConcurrencyProperty)
            {
                _concurrencyProperties.Add(dp);
            }

            return(dp);
        }
コード例 #3
0
        protected Object GetOriginalValue(DataProperty property)
        {
            object result;

            if (property.IsComplexProperty)
            {
                var co = (IComplexObject)GetValue(property, EntityVersion.Current);
                return(co.ComplexAspect.GetOriginalVersion());
            }
            else
            {
                if (_originalValuesMap != null && _originalValuesMap.TryGetValue(property.Name, out result))
                {
                    return(result);
                }
                else
                {
                    return(GetValue(property));
                }
            }
        }
コード例 #4
0
 protected void UpdateBackupVersion(DataProperty property, Object oldValue)
 {
     // We actually do want to track Proposed changes when Detached ( or Added) but we do not track an Original for either
     if (this.EntityState.IsAdded() || this.EntityState.IsDetached())
     {
         if (this.EntityVersion == EntityVersion.Proposed)
         {
             BackupProposedValueIfNeeded(property, oldValue);
         }
     }
     else
     {
         if (this.EntityVersion == EntityVersion.Current)
         {
             BackupOriginalValueIfNeeded(property, oldValue);
         }
         else if (this.EntityVersion == EntityVersion.Proposed)
         {
             // need to do both
             BackupOriginalValueIfNeeded(property, oldValue);
             BackupProposedValueIfNeeded(property, oldValue);
         }
     }
 }
コード例 #5
0
 /// <summary>
 /// Creates a new instance of UniqueId.
 /// </summary>
 /// <param name="property"></param>
 /// <param name="value"></param>
 public UniqueId(DataProperty property, Object value)
 {
     Property = property;
     Value    = value;
 }
コード例 #6
0
ファイル: ComplexAspect.cs プロジェクト: yayasoft/Breeze
 private void SetDpValueSimple(DataProperty property, object newValue, object oldValue)
 {
     // Actually set the value;
     SetRawValue(property.Name, newValue);
     UpdateBackupVersion(property, oldValue);
 }
コード例 #7
0
 internal virtual void OnDataPropertyRestore(DataProperty dp)
 {
     // deliberate noop here;
 }
コード例 #8
0
 protected internal abstract void SetDpValue(DataProperty dp, object newValue);