问题描述
我正在为显示在C#中使用LINQ客户生成报告。我想不显示。的每种类型的客户。
有3种类型的客户注册,来宾和经理。我想通过集团客户的登记日期,然后按客户类型的。即如果今天3位,4注册和2个经理插入。明天4,5和6都是注册教育储蓄计划。然后报告应该向客户展示registerd当天的数量。单独的行为每种类型。
日期TYPEOF客户COUNT
31-10-2013 GUEST 3
31-10-2013户籍4
31-10-2013 MANAGER 2
30-10-2013 GUEST 5
30-10-2013户籍10
30-10-2013 MANAGER 3
这样的。
VAR子查询=从吃_customerRepo.Table
按新{YY = eat.CreatedOnUTC.Value.Year,MM = eat.CreatedOnUTC.Value.Month,DD = eat.CreatedOnUTC.Value.Day}为G吃
选择新的{ID = g.Min(X => x.Id)};
VAR查询从C在_customerRepo.Table =
加入CIN在subquery.Distinct()上c.Id等于cin.Id
选择C;
通过上面的查询我得到的最低通知客户registerd在那一天
在此先感谢
VAR的查询= _customerRepo.Table
.GroupBy(C =>新建{日期= c.Date.Date,类型= c.TypeOfCustomer})
。选择(G =>新建
{
日期= g.Key.Date,
类型= g.Key.Type,
数= g.Count
}
)
.OrderByDescending相关(r = r.Date);
I am working on generating report for showing customer using LINQ in C#. I want to show no. of customers of each type.
There are 3 types of customer registered, guest and manager. I want to group by customers by registered date and then by type of customer. i.e If today 3 guest, 4 registered and 2 manager are inserted. and tomorrow 4,5 and 6 are registered resp. then report should show Number of customers registerd on the day . separate row for each type.
DATE TYPEOF CUSTOMER COUNT
31-10-2013 GUEST 3
31-10-2013 REGISTERED 4
31-10-2013 MANAGER 2
30-10-2013 GUEST 5
30-10-2013 REGISTERED 10
30-10-2013 MANAGER 3
LIKE THIS .
var subquery = from eat in _customerRepo.Table
group eat by new { yy = eat.CreatedOnUTC.Value.Year, mm = eat.CreatedOnUTC.Value.Month, dd = eat.CreatedOnUTC.Value.Day } into g
select new { Id = g.Min(x => x.Id) };
var query = from c in _customerRepo.Table
join cin in subquery.Distinct() on c.Id equals cin.Id
select c;
By above query I get minimum cutomers registerd on that dayThanks in advance
var query = _customerRepo.Table
.GroupBy(c => new {Date = c.Date.Date, Type = c.TypeOfCustomer})
.Select(g => new
{
Date = g.Key.Date,
Type = g.Key.Type,
Count = g.Count
}
)
.OrderByDescending (r = r.Date);
这篇关于LINQ按日期获取的客户群,然后通过它们的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!