Lambda
Join:
context.SoftwareModelVersion.Join(context.ModelVersion.Where(m=>m.ModelName==toolStripTextBox1.Text) , q => q.ModelVersoinID, p => p.ModelVersionID, (q, p) => new { SoftwareModelVersionID = q.SoftwareModelVersionID })
OrderBy:
var reuslt = group.OrderBy(q=>q.Attribute);
var reuslt = group.OrderByDescending(q=>q.Attribute);
连续排序:
var result = group.OrderByDescending(q=>q.Attribute).ThenBy(q=>q.Attribute2).ThenBy(q=>q.Attribute3);GroupBy:
GroupBy之后通常需要输出具包含统计信息的匿名集合,那么可以这样:
objCollection.GroupBy(q=>q.GroupByKey)
.Select(q=>new {Attribute1 = q.First().GroupByKey, Attribute2 = q.Sum(q.Value));
Select,SelectMany:
Select返回集合
SelectMany将序列的每个元素投影到 IEnumerable(T) 并将结果序列合并为一个序列。
class PetOwner
{
public string Name { get; set; }
public List<String> Pets { get; set; }
}
PetOwner[] petOwners =
{
new PetOwner { Name="Higa, Sidney",
Pets = new List<string>{ "Scruffy", "Sam" } },
new PetOwner { Name="Ashkenazi, Ronen",
Pets = new List<string>{ "Walker", "Sugar" } },
new PetOwner { Name="Price, Vernette",
Pets = new List<string>{ "Scratches", "Diesel" } }
};
// Query using SelectMany().
var query1 = petOwners.Select(petOwner => petOwner.Pets).ToList();
//返回List<List<string>>;
var query2 = petOwners.SelectMany(petOwner => petOwner.Pets).ToList();
//返回合并后的List<string>;
where:
var reuslt = group.Where(q=>q.Attribute.Equal(compareObject));
Aggregate:
string[] stra = new string[] { "Able", "was", "I", "ere", "I", "saw", "Elba"};
string aa = stra.Aggregate("",(a, n) => a + " " + n);
输出:
"Able was I ere I saw Elba"
欢迎C#或Winform技术交流,C#交流群:83868794