コード例 #1
0
ファイル: DBChangeTrackerInfo.cs プロジェクト: vumi846/TestPj
 public DBChangeTrackerInfo(DbEntityEntry dbEntity, System.Data.Entity.Core.Objects.ObjectContext objContext)
 {
     entity         = dbEntity.Entity;
     currentValues  = dbEntity.State == System.Data.Entity.EntityState.Deleted ? null : (DbPropertyValues)dbEntity.CurrentValues.Clone();
     originalValues = dbEntity.State == System.Data.Entity.EntityState.Added ? null : (DbPropertyValues)dbEntity.OriginalValues.Clone();
     state          = dbEntity.State;
     if (entity == null)
     {
         return;
     }
     #region GetEntityKeyValue
     string tblN = entity.GetType().Name;
     System.Data.Entity.Core.EntityKey key = objContext.CreateEntityKey(tblN, entity);
     DbKeyMember[] km = new DbKeyMember[key.EntityKeyValues.Length];
     for (int i = 0; i < key.EntityKeyValues.Length; i++)
     {
         km[i] = new DbKeyMember(key.EntityKeyValues[i].Key, key.EntityKeyValues[i].Value);
     }
     entityKey = new DbEntityKey(tblN, km);
     //Tracking changed data
     if (state == System.Data.Entity.EntityState.Modified && originalValues != null)
     {
         listRecordChanged = new List <DbRecordChangedInfo>();
         foreach (var fieldProperty in originalValues.PropertyNames)
         {
             if (dbEntity.Property(fieldProperty).IsModified)
             {
                 listRecordChanged.Add(new DbRecordChangedInfo(fieldProperty, originalValues[fieldProperty], currentValues[fieldProperty]));
             }
         }
     }
     #endregion
 }
コード例 #2
0
            // <Extension>
            // Public Function HasEntityKeyFirstValue(Of T As {Class, IEntityWithRelationships})(entityReference As EntityReference(Of T)) As Boolean
            // Return entityReference IsNot Nothing AndAlso entityReference.EntityKey.HasFirstValue(Of Integer)()
            // End Function

            // <Extension>
            // Public Function GetEntityKeyFirstValue(Of T As {Class, IEntityWithRelationships})(entityReference As EntityReference(Of T)) As Integer
            // If entityReference IsNot Nothing Then
            // Return entityReference.EntityKey.EntityKeyValues(GetEntityKeyFirstValue(Of Integer)()
            // End If
            // Return 0
            // End Function

            /// <summary>
            ///         ''' Gets the first entity key value
            ///         ''' </summary>
            ///         ''' <typeparam name="T"></typeparam>
            ///         ''' <param name="entityKey">The entity key.</param>
            ///         ''' <returns>the first entity key value</returns>
            public static T GetFirstValue <T>(this System.Data.Entity.Core.EntityKey entityKey)
            {
                if (entityKey != null && entityKey.EntityKeyValues != null && entityKey.EntityKeyValues.Length > 0)
                {
                    return((T)entityKey.EntityKeyValues.First().Value);
                }
                return(default(T));
            }
コード例 #3
0
 /// <summary>
 ///         ''' Sets the first entity key value
 ///         ''' </summary>
 ///         ''' <typeparam name="T"></typeparam>
 ///         ''' <param name="entityKey">The entity key.</param>
 ///         ''' <param name="value">The value.</param>
 public static void SetFirstValue <T>(this System.Data.Entity.Core.EntityKey entityKey, T value)
 {
     if (entityKey != null && entityKey.EntityKeyValues != null && entityKey.EntityKeyValues.Length > 0)
     {
         entityKey.EntityKeyValues.First().Value = value;
     }
     return;
 }
コード例 #4
0
        public virtual int Delete(T entity)
        {
            try
            {
                var fqen = GetEntityName <T>();

                object originalItem;
                System.Data.Entity.Core.EntityKey key = ((IObjectContextAdapter)Dbcontext).ObjectContext.CreateEntityKey(fqen, entity);
                if (((IObjectContextAdapter)Dbcontext).ObjectContext.TryGetObjectByKey(key, out originalItem))
                {
                    ((IObjectContextAdapter)Dbcontext).ObjectContext.DeleteObject(originalItem);
                }
                //_context.Set<T>().Attach(entity);
                //_context.Entry(entity).State = EntityState.Deleted;
                return(Save());
            }
            catch (Exception e)
            {
                throw;
            }
        }
コード例 #5
0
 /// <summary>
 ///         ''' Whether or not the entity key has a first value
 ///         ''' </summary>
 ///         ''' <typeparam name="T"></typeparam>
 ///         ''' <param name="entityKey">The entity key.</param>
 ///         ''' <returns><c>true</c> if [has first value] [the specified entity key]; otherwise, <c>false</c>.</returns>
 public static bool HasFirstValue <T>(this System.Data.Entity.Core.EntityKey entityKey)
 {
     return(!GetFirstValue <T>(entityKey).Equals(null));
 }