DDD领域模型企业级系统(三)

时间:2023-03-08 17:09:23
DDD领域模型企业级系统(三)

DDD领域模型企业级系统(三)

DDD领域模型企业级系统(三)

相关代码:

public static void ShowArray()
{
//数据源
int[] arrayas = new int[] { 1, 2, 3, 4 };
//创建查询
var query = from a in arrayas select a; foreach (var arraya in query)
{
Console.WriteLine(arraya.ToString());
}
} public static void ShowArrayWhere()
{
//数据源
int[] arrayas = new int[] { 1, 2, 3, 4 };
//创建查询
var query = from a in arrayas where(a%2==1)
select a; foreach (var arraya in query)
{
Console.WriteLine(arraya.ToString());
}
} public static void ShowArrayCount()
{
//数据源
int[] arrayas = new int[] { 1, 2, 3, 4 };
//创建查询
var query = from a in arrayas
where (a % 2 == 1)
select a; Console.WriteLine(query.Count());
} public static void ShowArrayList()
{
int[] arrayas = new int[] { 1, 2, 3, 4 };
var query = from a in arrayas
where (a % 2 == 1)
select a;
var querList = query.ToList();
foreach (var a in querList)
{
Console.WriteLine(a.ToString());
} } public class Student
{
public string Name { get; set; }
public string Classes { get; set; }
public List<int> Scores { get; set; }
} public static void CreateStudnet()
{
var students = new List<Student>()
{
new Student { Name="sunweiwei",Classes="classs1",Scores=
new List<int> { 90,80,60 } },
new Student {Name="shizhiwei",Classes="classs2",Scores=
new List<int> { 80,56,77} }
};
//创建查询 1.查询所有的学生 2.复合查询 3.放入 匿名对象中
var query = from s in students
from score in s.Scores
where s.Classes == "classs1" && score > 60
orderby score descending
select new { Name = s.Name, Score = score }; foreach (var student in query)
{
Console.WriteLine(student.Name + " " + student.Score);
}
} /// <summary>
/// 多个from查询
/// </summary>
public static void AndArray()
{
string[] arraya = new string[] { "aa", "bb" };
string[] arrayb = new string[] { "cc", "dd" }; var query = from a in arraya
from b in arrayb
select new { A=a, B=b };
foreach (var s in query)
{
Console.WriteLine(s.A+""+s.B);
}
} /// <summary>
/// Let
/// </summary>
public static void Let()
{
string[] arraya = new string[] { "aa", "bb" }; var query = from a in arraya
let A = a.ToUpper()
select A; foreach (var s in query)
{
Console.WriteLine(s);
}
} public static bool mo(int a)
{
return a % 2 == 1;
} public static void ShowArrayWhere1()
{
int[] arrayas = new int[] { 1, 2, 3, 4 };
var query = from a in arrayas
where mo(a)
select a;
foreach (var arraya in query)
{
Console.WriteLine(arraya.ToString());
}
} public static void CreateStudentOrderBy()
{
var students = new List<Student>()
{
new Student{ Name = "caojian", Classes = "classes1", Scores = new List<int> { 90, 80, 60 } },
new Student { Name = "ligang", Classes = "classes2", Scores = new List<int> { 80, 56, 77 } }
};
var query = from s in students
from score in s.Scores
orderby score descending
select new { Name = s.Name, Score = score };
foreach (var student in query)
{
Console.WriteLine(student.Name+" "+student.Score);
}
} public static void CreateStudentCreateBy()
{
var students = new List<Student>()
{
new Student{ Name = "caojian", Classes = "classes1", Scores = new List<int> { 90, 80, 60 } },
new Student { Name = "ligang", Classes = "classes2", Scores = new List<int> { 80, 56, 77 } }
};
var query = from s in students
from score in s.Scores
//存到范围变量中
group s by s.Classes into sclass
select sclass;
foreach (var student in query)
{
Console.WriteLine(student.Key);
}
}
  public class ProductCategory
{
public int CID { get; set; }
public string CName { get; set; }
} public class Product
{
public int PID { get; set; }
public string PName { get; set; }
public int CID { get; set; }
} public static void CreateCP()
{
var pcs = new List<ProductCategory>
{
new ProductCategory{ CID=1,CName="c1"}
};
var ps = new List<Product>
{
new Product{ PID=1,PName="p1",CID=1},
new Product{ PID=2,PName="p2",CID=1}
};
var query = from c in pcs
join p in ps on c.CID equals p.CID
select new { CName = c.CName, PName = p.PName };
foreach (var pc in query)
{
Console.WriteLine(pc.CName+" "+pc.PName);
}
} public static void CreateCPGroup()
{
var pcs = new List<ProductCategory>
{
new ProductCategory{ CID=1,CName="c1"}
};
var ps = new List<Product>
{
new Product{ PID=1,PName="p1",CID=1},
new Product{ PID=2,PName="p2",CID=1}
}; var query = from c in pcs
join p in ps on c.CID equals p.CID into pps
select new { CName = c.CName, pps };
foreach (var pc in query)
{
foreach (var p in pc.pps)
{
Console.WriteLine(pc.CName + " " + p.PName);
}
}
}
 public  class LinqToObject
{
public class Student
{
public string Name { get; set; }
public string Classes { get; set; }
public List<int> Scores { get; set; }
} public static void CreateStudnet()
{
var students = new ArrayList()
{ new Student { Name="sunweiwei",Classes="classs1",Scores=
new List<int> { 90,80,60 } },
new Student {Name="shizhiwei",Classes="classs2",Scores=
new List<int> { 80,56,77} }
};
//创建查询 1.查询所有的学生 2.复合查询 3.放入 匿名对象中
var query = from Student s in students
from score in s.Scores
where s.Classes == "classs1" && score > 60
orderby score descending
select new { Name = s.Name, Score = score }; foreach (var student in query)
{
Console.WriteLine(student.Name + " " + student.Score);
}
} public static List<Student> CreateStudentLamda()
{
var students = new List<Student>
{
new Student { Name="sunweiwei",Classes="classs1",Scores=
new List<int> { 90,80,60 } },
new Student {Name="shizhiwei",Classes="classs2",Scores=
new List<int> { 80,56,77} }
};
// var query = students.Where(p => p.Classes == "classs1").OrderBy(p => p.Classes).GroupBy(p => p.Classes);
var query = students.Where(p => p.Classes == "classs1");
//var query = students.Where(p => p.Classes == "classs1").Select(p => p.Classes.ToUpper());
return query.ToList(); } public static Student CreateStudentLamdal()
{
var students = new List<Student>
{
new Student { Name="sunweiwei",Classes="classs1",Scores=
new List<int> { 90,80,60 } },
new Student {Name="shizhiwei",Classes="classs2",Scores=
new List<int> { 80,56,77} }
};
// var query = students.Where(p => p.Classes == "classs1").OrderBy(p => p.Classes).GroupBy(p => p.Classes);
var query = students.Where(p => p.Classes == "classs1").SingleOrDefault(); return query; }
}
 private void btnshowstudent_Click(object sender, EventArgs e)
{
var studens = LINQObject.LinqToObject.CreateStudentLamda();
dgstudents.DataSource = studens; }