【发布时间】:2018-08-10 01:46:06
【问题描述】:
在这个问题上寻求一些帮助,我正在努力学习 linq 的工作原理。 我的想法是在 personID 上加入人员和客户列表以获取客户的名称,然后在 customerID 上加入客户和销售列表,然后在销售中计算 customerID 以获取来自在线的客户的销售量店铺。
任务:确定哪些人从我们的在线商店下的订单最多
public class Person
{
public int PersonID { get; set; }
public string PersonType { get; set; }
public bool NameStyle { get; set; }
public string Title { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string Suffix { get; set; }
}
public class Sale
{
public int SalesOrderId { get; set; }
public int RevisionNumber { get; set; }
public DateTime OrderDate { get; set; }
public DateTime DueDate { get; set; }
public DateTime? ShipDate { get; set; }
public bool IsOnlineOrder { get; set; }
public int CustomerId { get; set; }
public int? SalesPersonId { get; set; }
public int? TerritoryID { get; set; }
public decimal SubTotal { get; set; }
public decimal TaxAmt { get; set; }
public decimal Freight { get; set; }
public decimal TotalDue { get; set; }
}
public class Customer
{
//CustomerID can belong to a store or a person
public int CustomerID { get; set; }
public int? StoreID { get; set; }
public int? PersonID { get; set; }
public int? TerritoryID { get; set; }
public string AccountNumber { get; set; }
}
public void MostOrders()
{
List<Person> per = Data.GetAllPersons();
List<Sale> sale = Data.GetAllSales();
List<Customer> cus = Data.GetAllCustomers();
var join = (from x in per
join y in cus
on x.PersonID equals y.PersonID
join t in sale
on y.CustomerID equals t.CustomerId
select new
{
......
});
}
【问题讨论】: