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 ...
随机推荐
- 5.7.2.1 Math对象
ECMAScript还为保存数学公司公式和信息提供了一个公共位置,即Math对象.与我们在JavaScript直接编写的计算功能相比,Math对象提供的计算功能执行起来要快得多.Math对象中还提供了 ...
- zoj 2589 Matrix Searching 二维线段树
题目链接 给一个n*n的矩阵, 给q个查询, 每次给出x1, y1, x2, y2, 求这个矩阵中的最小值. 代码基本上和上一题相同... #include<bits/stdc++.h> ...
- 未能从程序集“System.ServiceModel, Version=3.0.0.0”中加载类型“System.ServiceModel.Activation.HttpModule” 的解决办法
未能从程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”中加载类型“ ...
- 了解常见的浏览器内核 Trident,Geckos,Presto,Webkit
了解常见的浏览器内核 Trident,Geckos,Presto,Webkit 内核只是一个通俗的说法,英文名称为"Layout engine",翻译过来就是"排版引擎& ...
- mysql 性别存储
大家在设计数据库时,碰到 性别.状态等 这些 值比较固定的列时,数据类型 是如何定义? 通常都是采用 : 1 create table `XXX` 2 ( 3 ........ 4 sex int(1 ...
- 繁简转换OpenCC,autogb 和 autob5,iconv,python的jianfan包
OpenCC OpenCC 是跨平台.多语言的开放中文转换库,除了基本的简繁转换功能外,用户还可以选择对不同用词习惯和异体字的处理方式. OpenCC 还提供方便的网页转换界面. OpenOffice ...
- Javascript 思维导图
学习的道路就是要不断的总结归纳,好记性不如烂笔头,so,下面将po出8张javascript相关的思维导图. 思维导图小tips:思维导图又叫心智图,是表达发射性思维的有效的图形思维工具 ,它简单却又 ...
- HUD 4473 Exam
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4473 题目意思 定义f(x) = 满足(a * b)|x的有序对(a,b)的个数. 然后输入一个n, ...
- externkeyword放到函数体内而导致的linkage问题
不少人都知道,C/C++语言编程时,假设要引用在别的C/C++文件里定义的变量或函数,必须extern一下,才干使用 另一些人知道,这个extern事实上能够放在函数体内声明,这么做的理由是不想让其它 ...
- mysql安装详细步骤图解
本文转自http://blog.csdn.net/fanyunlei/article/details/21454645 别看图多,其实mysql的安装十分简单,一路next即可,只是注意倒数第三步,设 ...