From 020b381d379fa1f7789aeefa1472457c6378e887 Mon Sep 17 00:00:00 2001
From: bicijinlian <bicijinlian@163.com>
Date: Sat, 7 Sep 2019 12:15:25 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 LinqStudy.Test/LinqToDataSet/DataSetDemo.cs   | 10 +++++
 LinqStudy.Test/LinqToDataSet/DataTableDemo.cs | 10 +++++
 LinqStudy.Test/LinqToObject/WhereTest.cs      | 42 +++++++++++++++++++
 LinqStudy.Test/LinqToSQL/Readme.txt           |  2 +
 LinqStudy.Test/LinqToXml/Person.xml           |  1 +
 LinqStudy.Test/Util/StringUtil.cs             | 11 +++++
 LinqStudy/Models/PersonEqual.cs               | 28 +++++++++++++
 7 files changed, 104 insertions(+)
 create mode 100644 LinqStudy.Test/LinqToDataSet/DataSetDemo.cs
 create mode 100644 LinqStudy.Test/LinqToDataSet/DataTableDemo.cs
 create mode 100644 LinqStudy.Test/LinqToObject/WhereTest.cs
 create mode 100644 LinqStudy.Test/LinqToSQL/Readme.txt
 create mode 100644 LinqStudy.Test/LinqToXml/Person.xml
 create mode 100644 LinqStudy.Test/Util/StringUtil.cs
 create mode 100644 LinqStudy/Models/PersonEqual.cs

diff --git a/LinqStudy.Test/LinqToDataSet/DataSetDemo.cs b/LinqStudy.Test/LinqToDataSet/DataSetDemo.cs
new file mode 100644
index 0000000..5a0bee6
--- /dev/null
+++ b/LinqStudy.Test/LinqToDataSet/DataSetDemo.cs
@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace LinqStudy.Test.LinqToDataSet
+{
+    public class DataSetDemo
+    {
+    }
+}
diff --git a/LinqStudy.Test/LinqToDataSet/DataTableDemo.cs b/LinqStudy.Test/LinqToDataSet/DataTableDemo.cs
new file mode 100644
index 0000000..1b5749e
--- /dev/null
+++ b/LinqStudy.Test/LinqToDataSet/DataTableDemo.cs
@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace LinqStudy.Test.LinqToDataSet
+{
+    public class DataTableDemo
+    {
+    }
+}
diff --git a/LinqStudy.Test/LinqToObject/WhereTest.cs b/LinqStudy.Test/LinqToObject/WhereTest.cs
new file mode 100644
index 0000000..62703c9
--- /dev/null
+++ b/LinqStudy.Test/LinqToObject/WhereTest.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Linq;
+using System.Linq.Expressions;
+
+using Xunit;
+
+namespace LinqStudy.Test.LinqToObject
+{
+    /// <summary>
+    /// where操作符:过滤查询条件
+    /// </summary>
+    public class WhereTest
+    {
+
+        [Fact]
+        public void Where_Test()
+        {
+            var Persons = new List<Person>()
+            {
+                new Person(){ Id=1,Name="zhangsan",Age=2},
+                new Person(){ Id =2,Name="lishi",Age=33}
+            };
+
+            var query = Persons.Where(p => p.Name.StartsWith("zhang"));
+            var age = query.FirstOrDefault()?.Age;
+
+            Assert.Equal(2, age);
+        }
+
+        [Fact]
+        public void Where_Argm_Test()
+        {
+            List<Person> Persons = null;
+
+            Action act = ()=> { Persons.Where(p => p.Name.StartsWith("zhang")); };
+
+            Assert.Throws<ArgumentNullException>(act);
+        }
+    }
+}
diff --git a/LinqStudy.Test/LinqToSQL/Readme.txt b/LinqStudy.Test/LinqToSQL/Readme.txt
new file mode 100644
index 0000000..f851d06
--- /dev/null
+++ b/LinqStudy.Test/LinqToSQL/Readme.txt
@@ -0,0 +1,2 @@
+
+Linq To SQL 与EF一起学习,不再单独列出。
\ No newline at end of file
diff --git a/LinqStudy.Test/LinqToXml/Person.xml b/LinqStudy.Test/LinqToXml/Person.xml
new file mode 100644
index 0000000..7dde50e
--- /dev/null
+++ b/LinqStudy.Test/LinqToXml/Person.xml
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="utf-8" ?> 
diff --git a/LinqStudy.Test/Util/StringUtil.cs b/LinqStudy.Test/Util/StringUtil.cs
new file mode 100644
index 0000000..9eeaf28
--- /dev/null
+++ b/LinqStudy.Test/Util/StringUtil.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace LinqStudy.Test.Util
+{
+    public static class StringUtil
+    {
+
+    }
+}
diff --git a/LinqStudy/Models/PersonEqual.cs b/LinqStudy/Models/PersonEqual.cs
new file mode 100644
index 0000000..9930af9
--- /dev/null
+++ b/LinqStudy/Models/PersonEqual.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace LinqStudy
+{
+    /// <summary>
+    /// Person自定义比较类
+    /// 各属性均同,则相等.有一个Null值则不相等。
+    /// </summary>
+    public class PersonEqual : IEqualityComparer<Person>
+    {
+        bool IEqualityComparer<Person>.Equals(Person x, Person y)
+        {
+            if (x==null || y==null)
+            {
+                return false;
+            }
+
+            return x.Id == y.Id && x.Name == y.Name && x.Age == y.Age;
+        }
+
+        int IEqualityComparer<Person>.GetHashCode(Person obj)
+        {
+            return (obj.Id+obj.Name+obj.Age).GetHashCode();
+        }
+    }
+}