开发者

How to retrive distinct month/year values from a table using LINQ to SQL [closed]

开发者 https://www.devze.com 2022-12-07 23:50 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help ce开发者_运维技巧nter. Closed 10 years ago.

In a blog engine system I need to show all Month/Year pair values which we have blog posts in (e.g. January 2009, February 2009, ...)

Is it possible in LINQ to SQL?


This will get the groupings. dates will be an IEnumerable of anonymous object that have a property "Month" and "Year".

  System.Globalization.DateTimeFormatInfo provider = new System.Globalization.DateTimeFormatInfo();
                SODataContext cnx = new SODataContext();
                var dates = from item in cnx.Projects
                            group item by new { item.DateColumn.Value.Year, item.DateColumn.Value.Month } into grouping
                            select new { Month = provider.GetMonthName(grouping.Key.Month), grouping.Key.Year};
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号