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 ...
随机推荐
- 一周学会Mootools 1.4中文教程:(7)汇总收尾
转眼之间已经第七课了,这也将成为最后一课,如果这7课下来您感觉水平没有达到预想的水平,没关系您可以继续关注本站的博文,我会陆续发一些类似的文章帮您提升水平,另外我最近打算和群里的几个Mootools爱 ...
- hdu 1524 A Chess Game 博弈
题目链接 给出一个有向无环图, 上面放有一些棋子, 两个人轮流移动棋子, 当一个人无法移动时, 算输. 求出每一个点的sg值, 异或就可以.出度为0的点sg值为0. #include<bits/ ...
- 使用VisualVM分析tomcat运行状况(1)
VisualVM是一款java程序性能分析与调优工具,而且还是jdk中自带的工具之一. tomcat也是一个java程序,自然也可以用它来进行监控.不过这里还是会有些问题,tomcat有两种常用的期待 ...
- Thml 小插件8 天气插件定制
网址:http://www.tianqi.com/plugin/
- stl 迭代子的失效
迭代子是STL中很重要的特性,但是其很脆弱(我个人认为),因为使用它的条件很苛刻,一不小心就失效了.其在两中情况下可能会失效. 1.当容器有插入操作时 在初始化了迭代子后,如果容器有插入操作时,迭代子 ...
- elk 日志处理的一点思路
zjtest7-frontend:/usr/local/logstash-2.3.4/bin# ./logstash -f ../config/logstash_agent.conf zjtest7- ...
- jquery-plugin-biggerLink,highLight-层加亮_andy 阳光生活_百度空间
How to get the xpath by clicking an html element How to get the xpath by clicking an html element Qu ...
- Hive Server 2 安装部署测试
Hive 0.11 包含了Hive Server 1 和 Hive Server 2,还包含1的原因是为了做到向下兼容性.从长远来看都会以Hive Server 2作为首选 1. 配置hive ser ...
- 第八届acm省赛 A挑战密室(模拟)
10406: A.挑战密室 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 29 Solved: 10 [Submit][Status][Web Bo ...
- pv ticketlock解决虚拟环境下的spinlock问题
最近看邮件,有注意到pv ticketlock相关的消息,貌似jeremy 几年前的东东,终于将要被收录到linux 3.12里面. 先说下pv ticketlock这东西,http://blog.x ...