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 +{ + /// + /// where操作符:过滤查询条件 + /// + public class WhereTest + { + + [Fact] + public void Where_Test() + { + var Persons = new List() + { + 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 Persons = null; + + Action act = ()=> { Persons.Where(p => p.Name.StartsWith("zhang")); }; + + Assert.Throws(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 @@ + 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 +{ + /// + /// Person自定义比较类 + /// 各属性均同,则相等.有一个Null值则不相等。 + /// + public class PersonEqual : IEqualityComparer + { + bool IEqualityComparer.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.GetHashCode(Person obj) + { + return (obj.Id+obj.Name+obj.Age).GetHashCode(); + } + } +}