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.的更多相关文章

  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. SQL 简单练习

    USE study; SELECT * FROM EMP --查询雇员姓名的最后三个字母 ) FROM EMP ; --查询10部门雇员进入公司的星期数 --1 查询部门30中的所有员工 --2 列出 ...

  2. phpUnit 断言

    转自http://blog.163.com/qianxue126@126/blog/static/162723138201119113131125/ 布尔类型assertTrue   断言为真asse ...

  3. ExtJS 修改load paging时的参数

    ExtJS 的pagingToolbar 在翻页的时候传入的参数是固定的  分别是start 和 limit(其中limit的值就是store.pageSize的值) 如何在每次翻页的时候传入自己的参 ...

  4. win7使用的一些误区以及困惑

    总结了一些新人在使用win7时容易产生的误区和困惑,罗列出来说明一下,以便新人能尽快适应新的操作系统. 1.内存使用的问题:这是个大误区,很多人都用xp时代的眼光来审视win7,这是错误的,因为两者的 ...

  5. NAND FLASH特性说明

    1.NAND FLASH 的特殊性. 1)存在坏块.由于NAND生产工艺的原因,出厂芯片中会随机出现坏块.坏块在出厂时已经被初始化,并在特殊区域中标记为不可用,在使用过程中如果出现坏块,也需要进行标记 ...

  6. 操作native window的QxtWindowSystem (好像是一个IM的一部分)

    http://libqxt.bitbucket.org/doc/0.6/qxtwindowsystem.html https://github.com/psi-plus/plugins/blob/ma ...

  7. HDU 5800 To My Girlfriend(单调DP)

    [题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=5800 [题目大意] 给出一个容量上限s,f[i][j][k][l][m]表示k和l两个物品不能选,i ...

  8. iOS加载HTML, CSS代码

    NSString *strHTML = @"<div style=\"text-align:center;\"><img src=\"/Upl ...

  9. linux内核源码阅读之facebook硬盘加速flashcache之四

    这一小节介绍一下flashcache读写入口和读写的基础实现. 首先,不管是模块还是程序,必须先找到入口,用户态代码会经常去先看main函数,内核看module_init,同样看IO流时候也要找到入口 ...

  10. WCF 双工通信

    注释:本学习是参考Artech大神的资料: 在WCF 实现双工通信 在这里我就不介绍双工通信的概念了,我写博客的目的是检测自己掌握情况,看我wcf通信后,觉得纸上得来终觉浅,绝知此事要躬行. 我使用的 ...