From cf5ad4c7f3526ce86705e04320034a082a6d976d Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Sun, 14 Oct 2018 13:20:10 +0800 Subject: [PATCH] - --- Src/Asp.Net/SqlServerTest/Demos/G_Mapper.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Src/Asp.Net/SqlServerTest/Demos/G_Mapper.cs b/Src/Asp.Net/SqlServerTest/Demos/G_Mapper.cs index 4f615e2ff..ccf18b2ae 100644 --- a/Src/Asp.Net/SqlServerTest/Demos/G_Mapper.cs +++ b/Src/Asp.Net/SqlServerTest/Demos/G_Mapper.cs @@ -24,7 +24,7 @@ namespace OrmTest.Demo var allSchools = cache.GetListByPrimaryKeys(vmodel => vmodel.SchoolId);//in(ViewModelStudent3[0].SchoolId , ViewModelStudent3[1].SchoolId...) - //Equal to the following writing. + //Equal to allSchools //var allSchools2= cache.Get(list => // { // var ids=list.Select(i => it.SchoolId).ToList(); @@ -32,11 +32,19 @@ namespace OrmTest.Demo //});Complex writing metho + /*one to one*/ + //Good performance + it.School = allSchools.FirstOrDefault(i => i.Id == it.SchoolId); - it.School = allSchools.FirstOrDefault(i => i.Id == it.SchoolId);//one to one + //Poor performance. + //it.School = db.Queryable().InSingle(it.SchoolId); - it.Schools = allSchools.Where(i => i.Id == it.SchoolId).ToList();//one to many + /*one to many*/ + it.Schools = allSchools.Where(i => i.Id == it.SchoolId).ToList(); + + + /*C# syntax conversion*/ it.Name = it.Name == null ? "null" : it.Name; }).ToList();