Compare the value of entity field.
- public class Program
- {
- static void Main(string[] args)
- {
- Program p = new Program();
- p.Test();
- Console.ReadLine();
- }
- public void Test()
- {
- List<People> initPeopleList = new List<People>();
- People people = new People("Richy",25,"Shanghai");
- initPeopleList.Add(people);
- people = new People("Sherry",25,"Shanghai");
- initPeopleList.Add(people);
- List<People> newPeopleList = new List<People>();
- people = new People("Kim",25,"Shanghai");
- newPeopleList.Add(people);
- if (CompareEntity(initPeopleList, newPeopleList))
- {
- Console.WriteLine("The two entity has some field is not equal.");
- }
- else
- {
- Console.WriteLine("The two entity are the same.");
- }
- }
- public bool CompareEntity(List<People> initPeopleList,List<People> newPeopleList)
- {
- bool DiffFlag = false;
- if (initPeopleList != null && newPeopleList != null)
- {
- List<PropertyInfo> infoList = typeof(People).GetProperties().ToList();
- foreach (var initPeople in initPeopleList)
- {
- var commonList = newPeopleList.Where(s => (s.Id == initPeople.Id)).FirstOrDefault(); //We assume id is the primary key.
- if (commonList != null)
- {
- foreach (var propertyInfo in infoList)
- {
- var initValue = initPeople.GetType().GetProperty(propertyInfo.Name).GetValue(initPeople, null);
- var newValue = commonList.GetType().GetProperty(propertyInfo.Name).GetValue(commonList, null);
- if (initValue != null && !initValue.Equals(newValue))
- {
- DiffFlag = true;
- break;
- }
- }
- }
- else
- {
- DiffFlag = true;
- break;
- }
- }
- }
- else if((initPeopleList == null || newPeopleList == null) && (initPeopleList!=newPeopleList))
- {
- DiffFlag=true;
- }
- return DiffFlag;
- }
- }
- public class People
- {
- public string EnglishName { get; set; }
- public int Id { get; set; }
- public string Address { get; set; }
- public People(string name, int Id, string address)
- {
- this.EnglishName = name;
- this.Id = Id;
- this.Address = address;
- }
- }
Compare the value of entity field.的更多相关文章
- [转]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 ...
- Open CASCADE Technology: IGES Support
2015/6/4 Open CASCADE Technology: IGES Support http://www.opencascade.org/doc/occt6.7.0/overview/ht ...
- CodeIgniter 下引入ORM Doctrine
做了两年的CI开发,一直使用activeRecord来操作数据库.简单,轻巧加方便.最近一个项目交给手下去做,也是采用从数据库设计入手的开发流程,现在已经上线运行.经历了理清需求,设计数据库,在CI中 ...
- 在Asp.Net MVC中实现CompareValues标签对Model中的属性进行验证
在Asp.Net MVC中可以用继承ValidationAttribute的方式,自定制实现Model两个中两个属性值的比较验证 具体应用场景为:要对两个属性值的大小进行验证 代码如下所示: /// ...
- avalon---qunar ued
http://avalonjs.github.io/ http://ued.qunar.com/ https://github.com/RubyLouvre/avalon 1.前后端分离-- 2.gr ...
- ofbiz进击 第三节。 各个关键文件的说明与作用
1. entityengine.xml 数据引擎文件 用于配置数据库链接设置 <group-map group-name="org.ofbiz" datasource- ...
- Solr DIH dataconfig配置
1. 配置文件data-config.xml定义了数据库的基本配置,以及导出数据的映射规则,即导出数据库表中对应哪些字段的值,以及对特定字段的值做如何处理 </pre><p>& ...
- DIH处理包含回车符换行符html标签内容的文本
数据样例:2010-03-19 10:18:06130010543234203guqun09-12月-12liuyin18-6月 -14<P style="MARGIN-TOP: 0p ...
- 宏btr_pcur_open_on_user_rec
参考http://wqtn22.iteye.com/blog/1820436 http://blog.jcole.us/2013/01/10/btree-index-structures-in-inn ...
随机推荐
- js函数绑定同时,如何保留代码执行环境?
经常写js的程序员一定不会对下面这段代码感到陌生. var EventUtil = { addHandler : function(element, type, handler){ if(elemen ...
- QT 一些非常常用的操作
一 如果在窗体关闭前自行判断是否可关闭二 如何用打开和保存文件对话框 三 如何使用警告.信息等对话框 四 在Windows下Qt里为什么没有终端输出五 想在源代码中直接使用中文 ...
- JavaEE Tutorials (15) - 对Java持久化API应用使用二级缓存
15.1二级缓存概述190 15.1.1控制实体是否可以缓存19115.2指定缓存模式设置来提高性能192 15.2.1设置缓存获取和存储模式192 15.2.2通过编程方式控制二级缓存194
- aliyun 镜像
[epel]name=Extra Packages for Enterprise Linux 6 - $basearchbaseurl=http://mirrors.aliyun.com/epel/6 ...
- xcode 工具栏中放大镜的替换的简单说明
1.如果是在打开的文档范围内: 查找: Command+ F 替换: Option+Command+F Replace All 是全部替 ...
- .net-一般处理程序及生命周期
IsReusable属性用来表示在IHttpHandlerFactory对象创建IHttpHandler的时候是否能够将这个Handler存入池中以便重用. 一般处理程序(HttpHandler):是 ...
- java中如何计算两个时间段的月份差
直接计算,先取得两个日期的年份和月份,月份差=(第二年份-第一年份)*12 + 第二月份-第一月份
- Struts学习之值栈的理解
转自:http://blog.csdn.net/hanxuemin12345/article/details/38559979 页面一个请求发送过来,依次经过一系列拦截器(处理公共部分,如:往数据中心 ...
- java 实现 一个账号只能在一个地方登陆,其他地方被下线
其实方法有很多的,我这献丑了. 使用理解java 四大作用域. 思路:理解java 四大作用域的关键. 第一个地方登陆: 1.得到请求的SessionId 和 登陆的 用户名 2.把SessionId ...
- bzoj 1295: [SCOI2009]最长距离
题目链接 1295: [SCOI2009]最长距离 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1165 Solved: 619[Submit][ ...