Exemple #1
0
 private static void CheckForInvalidChanges(TrackedObject tracked)
 {
     foreach (MetaDataMember member in tracked.Type.PersistentDataMembers)
     {
         if (((member.IsPrimaryKey || member.IsDbGenerated) || member.IsVersion) &&
             tracked.HasChangedValue(member))
         {
             if (member.IsPrimaryKey)
             {
                 throw Error.IdentityChangeNotAllowed(member.Name, tracked.Type.Name);
             }
             throw Error.DbGeneratedChangeNotAllowed(member.Name, tracked.Type.Name);
         }
     }
 }
Exemple #2
0
            private static Expression GetUpdateCheck(Expression serverItem, TrackedObject tracked)
            {
                MetaType type = tracked.Type;

                if (type.VersionMember != null)
                {
                    return(Expression.Equal(GetMemberExpression(serverItem, type.VersionMember.Member), GetMemberExpression(Expression.Constant(tracked.Current), type.VersionMember.Member)));
                }
                Expression left = null;

                foreach (MetaDataMember member in type.PersistentDataMembers)
                {
                    if (!member.IsPrimaryKey)
                    {
                        UpdateCheck updateCheck = member.UpdateCheck;
                        if ((updateCheck == UpdateCheck.Always) || ((updateCheck == UpdateCheck.WhenChanged) && tracked.HasChangedValue(member)))
                        {
                            object     boxedValue = member.MemberAccessor.GetBoxedValue(tracked.Original);
                            Expression right      = Expression.Equal(GetMemberExpression(serverItem, member.Member), Expression.Constant(boxedValue, member.Type));
                            left = (left != null) ? Expression.And(left, right) : right;
                        }
                    }
                }
                return(left);
            }