예제 #1
0
        public static bool IsConcurrencyTimestamp(EdmMember member)
        {
            Facet facet = member.TypeUsage.Facets.FirstOrDefault((Facet p) => p.Name == "ConcurrencyMode");

            if (facet == null || facet.Value == null || (ConcurrencyMode)facet.Value != ConcurrencyMode.Fixed)
            {
                return(false);
            }
            facet = member.TypeUsage.Facets.FirstOrDefault((Facet p) => p.Name == "FixedLength");
            if (facet == null || facet.Value == null || !(bool)facet.Value)
            {
                return(false);
            }
            facet = member.TypeUsage.Facets.FirstOrDefault((Facet p) => p.Name == "MaxLength");
            if (facet == null || facet.Value == null || (int)facet.Value != 8)
            {
                return(false);
            }
            MetadataProperty storeGeneratedPattern = ObjectContextUtilities.GetStoreGeneratedPattern(member);

            return(storeGeneratedPattern != null && facet.Value != null && !((string)storeGeneratedPattern.Value != "Computed"));
        }
예제 #2
0
        public static void AttachAsModified <T>(this DbSet <T> dbSet, T current, T original, DbContext dbContext) where T : class
        {
            if (dbSet == null)
            {
                throw new ArgumentNullException("dbSet");
            }
            if (current == null)
            {
                throw new ArgumentNullException("current");
            }
            if (original == null)
            {
                throw new ArgumentNullException("original");
            }
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext");
            }
            DbEntityEntry <T> dbEntityEntry = dbContext.Entry <T>(current);

            if (dbEntityEntry.State == EntityState.Detached)
            {
                dbSet.Attach(current);
            }
            else
            {
                dbEntityEntry.State = EntityState.Modified;
            }
            ObjectContext    objectContext    = ((IObjectContextAdapter)dbContext).ObjectContext;
            ObjectStateEntry objectStateEntry = ObjectContextUtilities.AttachAsModifiedInternal <T>(current, original, objectContext);

            if (objectStateEntry.State != EntityState.Modified)
            {
                dbEntityEntry.State = EntityState.Modified;
            }
        }