1. public class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. Program p = new Program();
  6. p.Test();
  7. Console.ReadLine();
  8. }
  9.  
  10. public void Test()
  11. {
  12. List<People> initPeopleList = new List<People>();
  13. People people = new People("Richy",25,"Shanghai");
  14. initPeopleList.Add(people);
  15. people = new People("Sherry",25,"Shanghai");
  16. initPeopleList.Add(people);
  17.  
  18. List<People> newPeopleList = new List<People>();
  19. people = new People("Kim",25,"Shanghai");
  20. newPeopleList.Add(people);
  21. if (CompareEntity(initPeopleList, newPeopleList))
  22. {
  23. Console.WriteLine("The two entity has some field is not equal.");
  24. }
  25. else
  26. {
  27. Console.WriteLine("The two entity are the same.");
  28. }
  29. }
  30. public bool CompareEntity(List<People> initPeopleList,List<People> newPeopleList)
  31. {
  32. bool DiffFlag = false;
  33. if (initPeopleList != null && newPeopleList != null)
  34. {
  35. List<PropertyInfo> infoList = typeof(People).GetProperties().ToList();
  36. foreach (var initPeople in initPeopleList)
  37. {
  38. var commonList = newPeopleList.Where(s => (s.Id == initPeople.Id)).FirstOrDefault(); //We assume id is the primary key.
  39. if (commonList != null)
  40. {
  41. foreach (var propertyInfo in infoList)
  42. {
  43. var initValue = initPeople.GetType().GetProperty(propertyInfo.Name).GetValue(initPeople, null);
  44. var newValue = commonList.GetType().GetProperty(propertyInfo.Name).GetValue(commonList, null);
  45. if (initValue != null && !initValue.Equals(newValue))
  46. {
  47. DiffFlag = true;
  48. break;
  49. }
  50. }
  51. }
  52. else
  53. {
  54. DiffFlag = true;
  55. break;
  56. }
  57. }
  58. }
  59. else if((initPeopleList == null || newPeopleList == null) && (initPeopleList!=newPeopleList))
  60. {
  61. DiffFlag=true;
  62. }
  63.  
  64. return DiffFlag;
  65. }
  66.  
  67. }
  68.  
  69. public class People
  70. {
  71. public string EnglishName { get; set; }
  72. public int Id { get; set; }
  73. public string Address { get; set; }
  74.  
  75. public People(string name, int Id, string address)
  76. {
  77. this.EnglishName = name;
  78. this.Id = Id;
  79. this.Address = address;
  80. }
  81. }

  

Compare the value of entity field.的更多相关文章

  1. [转]How to query posts filtered by custom field values

    Description It is often necessary to query the database for a list of posts based on a custom field ...

  2. Open CASCADE Technology: IGES Support

    2015/6/4 Open CASCADE Technology: IGES Support http://www.opencascade.org/doc/occt­6.7.0/overview/ht ...

  3. CodeIgniter 下引入ORM Doctrine

    做了两年的CI开发,一直使用activeRecord来操作数据库.简单,轻巧加方便.最近一个项目交给手下去做,也是采用从数据库设计入手的开发流程,现在已经上线运行.经历了理清需求,设计数据库,在CI中 ...

  4. 在Asp.Net MVC中实现CompareValues标签对Model中的属性进行验证

    在Asp.Net MVC中可以用继承ValidationAttribute的方式,自定制实现Model两个中两个属性值的比较验证 具体应用场景为:要对两个属性值的大小进行验证 代码如下所示: /// ...

  5. avalon---qunar ued

    http://avalonjs.github.io/ http://ued.qunar.com/ https://github.com/RubyLouvre/avalon 1.前后端分离-- 2.gr ...

  6. ofbiz进击 第三节。 各个关键文件的说明与作用

    1.  entityengine.xml   数据引擎文件 用于配置数据库链接设置 <group-map group-name="org.ofbiz" datasource- ...

  7. Solr DIH dataconfig配置

    1. 配置文件data-config.xml定义了数据库的基本配置,以及导出数据的映射规则,即导出数据库表中对应哪些字段的值,以及对特定字段的值做如何处理 </pre><p>& ...

  8. DIH处理包含回车符换行符html标签内容的文本

    数据样例:2010-03-19 10:18:06130010543234203guqun09-12月-12liuyin18-6月 -14<P style="MARGIN-TOP: 0p ...

  9. 宏btr_pcur_open_on_user_rec

    参考http://wqtn22.iteye.com/blog/1820436 http://blog.jcole.us/2013/01/10/btree-index-structures-in-inn ...

随机推荐

  1. js函数绑定同时,如何保留代码执行环境?

    经常写js的程序员一定不会对下面这段代码感到陌生. var EventUtil = { addHandler : function(element, type, handler){ if(elemen ...

  2. QT 一些非常常用的操作

    一   如果在窗体关闭前自行判断是否可关闭二   如何用打开和保存文件对话框  三   如何使用警告.信息等对话框  四   在Windows下Qt里为什么没有终端输出五   想在源代码中直接使用中文 ...

  3. JavaEE Tutorials (15) - 对Java持久化API应用使用二级缓存

    15.1二级缓存概述190 15.1.1控制实体是否可以缓存19115.2指定缓存模式设置来提高性能192 15.2.1设置缓存获取和存储模式192 15.2.2通过编程方式控制二级缓存194

  4. aliyun 镜像

    [epel]name=Extra Packages for Enterprise Linux 6 - $basearchbaseurl=http://mirrors.aliyun.com/epel/6 ...

  5. xcode 工具栏中放大镜的替换的简单说明

    1.如果是在打开的文档范围内:       查找: Command+ F       替换: Option+Command+F                   Replace All   是全部替 ...

  6. .net-一般处理程序及生命周期

    IsReusable属性用来表示在IHttpHandlerFactory对象创建IHttpHandler的时候是否能够将这个Handler存入池中以便重用. 一般处理程序(HttpHandler):是 ...

  7. java中如何计算两个时间段的月份差

    直接计算,先取得两个日期的年份和月份,月份差=(第二年份-第一年份)*12 + 第二月份-第一月份

  8. Struts学习之值栈的理解

    转自:http://blog.csdn.net/hanxuemin12345/article/details/38559979 页面一个请求发送过来,依次经过一系列拦截器(处理公共部分,如:往数据中心 ...

  9. java 实现 一个账号只能在一个地方登陆,其他地方被下线

    其实方法有很多的,我这献丑了. 使用理解java 四大作用域. 思路:理解java 四大作用域的关键. 第一个地方登陆: 1.得到请求的SessionId 和 登陆的 用户名 2.把SessionId ...

  10. bzoj 1295: [SCOI2009]最长距离

    题目链接 1295: [SCOI2009]最长距离 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1165  Solved: 619[Submit][ ...