NewLife/X

必须填写至少10个字的日志
nnhy authored at 2012-07-27 18:48:21
1ebdc6b
Tree
1 Parent(s) e7918f5
Summary: 4 changed files with 29 additions and 6 deletions.
Modified +17 -1
Modified +7 -4
Modified +3 -1
Modified +2 -0
Modified +17 -1
diff --git a/XCode/Entity/Entity.cs b/XCode/Entity/Entity.cs
index dc519d5..f3ee6b9 100644
--- a/XCode/Entity/Entity.cs
+++ b/XCode/Entity/Entity.cs
@@ -92,6 +92,10 @@ namespace XCode
                     }
                 }
             }
+            foreach (EntityBase entity in list)
+            {
+                entity._IsFromDatabase = true;
+            }
             if (list is EntityList<TEntity>) return list as EntityList<TEntity>;
 
             return new EntityList<TEntity>(list);
@@ -99,7 +103,14 @@ namespace XCode
 
         /// <summary>��һ�������ж���������ݡ������ع�������</summary>
         /// <param name="dr">������</param>
-        public override void LoadData(DataRow dr) { if (dr != null) dreAccessor.LoadData(dr, this); }
+        public override void LoadData(DataRow dr)
+        {
+            if (dr != null)
+            {
+                dreAccessor.LoadData(dr, this);
+                _IsFromDatabase = true;
+            }
+        }
 
         /// <summary>�������ݶ�д����������ʱ���ؿռ��϶�����null��</summary>
         /// <param name="dr">���ݶ�д��</param>
@@ -120,6 +131,10 @@ namespace XCode
                     }
                 }
             }
+            foreach (EntityBase entity in list)
+            {
+                entity._IsFromDatabase = true;
+            }
             if (list is EntityList<TEntity>) return list as EntityList<TEntity>;
 
             return new EntityList<TEntity>(list);
@@ -132,6 +147,7 @@ namespace XCode
             if (dr != null)
             {
                 dreAccessor.LoadData(dr, this);
+                _IsFromDatabase = true;
 
                 // ����Ĭ���ۼ��ֶ�
                 var fs = AdditionalFields;
Modified +7 -4
diff --git a/XCode/Entity/EntityBase_Interface.cs b/XCode/Entity/EntityBase_Interface.cs
index 3a4b189..17724b5 100644
--- a/XCode/Entity/EntityBase_Interface.cs
+++ b/XCode/Entity/EntityBase_Interface.cs
@@ -12,6 +12,9 @@ namespace XCode
     //, IDataErrorInfo
     {
         #region INotifyPropertyChanged接口
+        /// <summary>如果实体来自数据库,在给数据属性赋相同值时,不改变脏数据,其它情况均改变脏数据</summary>
+        internal protected Boolean _IsFromDatabase;
+
         /// <summary>属性改变。重载时记得调用基类的该方法,以设置脏数据属性,否则数据将无法Update到数据库。</summary>
         /// <param name="fieldName">字段名</param>
         /// <param name="newValue">新属性值</param>
@@ -22,14 +25,14 @@ namespace XCode
             //            if (_PropertyChanging != null) _PropertyChanging(this, new PropertyChangingEventArgs(fieldName));
             //#endif
             // 如果数据没有改变,不应该影响脏数据
-            if (!Object.Equals(this[fieldName], newValue))
+            if (_IsFromDatabase && Object.Equals(this[fieldName], newValue))
             {
-                Dirtys[fieldName] = true;
-                return true;
+                return false;
             }
             else
             {
-                return false;
+                Dirtys[fieldName] = true;
+                return true;
             }
         }
 
Modified +3 -1
diff --git a/XCode/Properties/AssemblyInfo.cs b/XCode/Properties/AssemblyInfo.cs
index 7ffea37..0e38ac7 100644
--- a/XCode/Properties/AssemblyInfo.cs
+++ b/XCode/Properties/AssemblyInfo.cs
@@ -35,7 +35,7 @@ using System.Runtime.InteropServices;
 // 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
 // 方法是按如下所示使用“*”:
 [assembly: AssemblyVersion("8.8.*")]
-[assembly: AssemblyFileVersion("8.8.2012.0722")]
+[assembly: AssemblyFileVersion("8.8.2012.0727")]
 
 /*
  * XCode的重大改进
@@ -52,6 +52,8 @@ using System.Runtime.InteropServices;
  * /
 
 /*
+ * v8.8.2012.0727   如果实体来自数据库,在给数据属性赋相同值时,不改变脏数据,其它情况均改变脏数据
+ * 
  * v8.8.2012.0722   增加模型字段排序特性ModelSortModeAttribute,默认指定基类数据字段优先,影响生成数据表字段顺序
  * 
  * v8.8.2012.0718   增加实体事务区域EntityTransaction
Modified +2 -0
diff --git a/XCode/UpdateInfo.txt b/XCode/UpdateInfo.txt
index e33cf46..f5ad0d9 100644
--- a/XCode/UpdateInfo.txt
+++ b/XCode/UpdateInfo.txt
@@ -10,6 +10,8 @@ v2.0 数据架构功能,实体和数据结构双向映射
 v1.2 使用泛型基类
 v1.0 创建XCode
 
+v8.8.2012.0727   如果实体来自数据库,在给数据属性赋相同值时,不改变脏数据,其它情况均改变脏数据
+
 v8.8.2012.0722   增加模型字段排序特性ModelSortModeAttribute,默认指定基类数据字段优先,影响生成数据表字段顺序
 
 v8.8.2012.0718   增加实体事务区域EntityTransaction