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 ...
随机推荐
- websocket 通信协议
//WEBSOKET java SERVICE http://my.oschina.net/u/590484/blog/71797 UPDATE:前些天有网友mail和我讨论websocket协议,当 ...
- codeforces 633C. Spy Syndrome 2 hash
题目链接 C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Dockerfile
http://blog.csdn.net/jiashiwen/article/details/48806243 一:如何使用: Dockerfile 用来创建一个自定义的image,包含了用户指定的软 ...
- linux之awk
相较于sed 常常作用于一整个行的处理,awk 则比较倾向于一行当中分成数个『字段』来处理. 因此,awk 相当的适合处理小型的数据数据处理呢! awk 通常运作的模式是这样的: [root@linu ...
- SQL Server ansi_null_default | ansi_null_dflt_on
先说一下这两个变量是一个意思,只是它们的作用范围不同 alter database dbTest set ansi_null_default on; -- 这个的作用域是整个SQL Server ...
- 简单介绍一下ODI的几个基本概念
简单介绍一下ODI的几个基本概念 ODI的几个基本概念是本文我们主要要介绍的内容,接下来我们就开始介绍这一过程,一起来看看吧! 什么是资料库 ODI资料库可安装在任何支持ANSIISO89的数据库 ...
- JS HTML DOM
HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). HTML DOM 模型被构造为对象的树. HTML DOM 树 通过 ...
- C#中数组、ArrayList和List三者的区别(转)
好东西,总结的很到位,收藏了! 源地址:http://blog.csdn.net/zhang_xinxiu/article/details/8657431
- .Net MVC 入门之Razor语法
Razor语法 Razor是以后MVC项目中都需要用的, 所以在学MVC的基础的时候,我们的目标:要了解熟悉Razor页面的语法结构,做到灵活使用,so我们马上开始学习Razor,也请你们多评论和推荐 ...
- hdu 2203亲和串 (kmp)
#include<cstdio>#include<iostream>#include<cstring>#include<string>using nam ...