igrouping

ILookup<TKey, TVal> vs. IGrouping<TKey, TVal>

旧城冷巷雨未停 提交于 2019-12-17 07:11:08
问题 I've been having trouble articulating the differences between ILookup<TKey, TVal> and IGrouping<TKey, TVal>, and am curious if I understand it correctly now. LINQ compounded the issue by producing sequences of IGrouping items while also giving me a ToLookup extension method. So it felt like they were the same until I looked more closely. var q1 = from n in N group n by n.MyKey into g select g; // q1 is IEnumerable<IGrouping<TKey, TVal>> Which is equivalent to: var q2 = N.GroupBy(n => n.MyKey,

How to order IGrouping without changing its type?

£可爱£侵袭症+ 提交于 2019-12-14 03:48:40
问题 I have an oject of the type IGrouping and would like to order the elements inside the group without changing the type of the object. In other words, I have var tmp = group.OrderBy(x => x); with group being of type IGrouping<int, someanonymousclass> and I want tmp to be of type IGrouping<int, someanonymousclass> as well. One workaround would be to change it to a Dictionary or a new anonymous class, but I want tmp to specificly be of type IGrouping<int, someanonymousclass> . In other words: I

Mapping a grouped collection using AutoMapper

不羁岁月 提交于 2019-12-12 11:05:13
问题 I have the following code which is not working: var groupedZones = this._zoneDataManager.GetZonesGroupedByCountry(); IEnumerable<IGrouping<String, ZoneDTO>> zonesToReturn = Mapper.Map<IEnumerable<IGrouping<String, Zone>>, IEnumerable<IGrouping<String, ZoneDTO>>>(groupedZones); I keep getting the following exception: The value \"System.Collections.Generic.List 1[SCGRE.Business.Model.ZoneDTO]\" is not of type \"System.Linq.IGrouping 2[System.String,SCGRE.Business.Model.ZoneDTO]\" and cannot be

Return IGrouping of anonymous IEnumerable to present on DataGrid

▼魔方 西西 提交于 2019-12-06 17:43:29
问题 On WPF I build this code I want to show on datagrid the sum of "Desc" for each "PID" public class Event { public int PID { get; set; } public int Desc { get; set; } } private List<Event> data; public MainWindow() { InitializeComponent(); data = new List<Event>() { new Event() { PID = 1, Desc=2 }, new Event() { PID = 1, Desc=3 }, new Event() { PID = 2, Desc=4 }, new Event() { PID = 2, Desc=5 }, new Event() { PID = 3, Desc=6 } }; var result = from d in data group d.Desc by d.PID into pg select

LINQ: Grouping SubGroup

半世苍凉 提交于 2019-12-06 06:10:53
问题 How to group SubGroup to create list of Continents where each Continent has it own counties and each country has its own cities like this table Here is the t-sql: select Continent.ContinentName, Country.CountryName, City.CityName from Continent left join Country on Continent.ContinentId = Country.ContinentId left join City on Country.CountryId = City.CountryId and the result of t-sql: I tried this but it groups the data in wrong way i need to group exactly like the above table var Result =

Return IGrouping of anonymous IEnumerable to present on DataGrid

北城余情 提交于 2019-12-04 21:49:35
On WPF I build this code I want to show on datagrid the sum of "Desc" for each "PID" public class Event { public int PID { get; set; } public int Desc { get; set; } } private List<Event> data; public MainWindow() { InitializeComponent(); data = new List<Event>() { new Event() { PID = 1, Desc=2 }, new Event() { PID = 1, Desc=3 }, new Event() { PID = 2, Desc=4 }, new Event() { PID = 2, Desc=5 }, new Event() { PID = 3, Desc=6 } }; var result = from d in data group d.Desc by d.PID into pg select new { ID = pg.Key, SUM = pg.Sum() }; datagrid.ItemsSource = result; } And the XAML is <DataGrid Name=

LINQ: Grouping SubGroup

眉间皱痕 提交于 2019-12-04 10:29:33
How to group SubGroup to create list of Continents where each Continent has it own counties and each country has its own cities like this table Here is the t-sql: select Continent.ContinentName, Country.CountryName, City.CityName from Continent left join Country on Continent.ContinentId = Country.ContinentId left join City on Country.CountryId = City.CountryId and the result of t-sql: I tried this but it groups the data in wrong way i need to group exactly like the above table var Result = MyRepository.GetList<GetAllCountriesAndCities>("EXEC sp_GetAllCountriesAndCities"); List<Continent> List

ILookup<TKey, TVal> vs. IGrouping<TKey, TVal>

﹥>﹥吖頭↗ 提交于 2019-11-27 03:09:47
I've been having trouble articulating the differences between ILookup<TKey, TVal> and IGrouping<TKey, TVal> , and am curious if I understand it correctly now. LINQ compounded the issue by producing sequences of IGrouping items while also giving me a ToLookup extension method. So it felt like they were the same until I looked more closely. var q1 = from n in N group n by n.MyKey into g select g; // q1 is IEnumerable<IGrouping<TKey, TVal>> Which is equivalent to: var q2 = N.GroupBy(n => n.MyKey, n => n); // q2 is IEnumerable<IGrouping<TKey, TVal>> Which looks a lot like: var q3 = N.ToLookup(n =>

How to get values from IGrouping

依然范特西╮ 提交于 2019-11-26 18:29:07
I have a question about IGrouping and Select() method. Lets say I've got IEnumerable<IGrouping<int, smth>> in this way: var groups = list.GroupBy(x => x.ID); where list is a List<smth> . And now I need to pass values of each IGrouping to another list in some way.: foreach (var v in structure) { v.ListOfSmth = groups.Select(...); // <- ??? } Can anybody suggest how to get values ( List<smth> ) from IGrouping<int, smth> in such context? Matt Smith Since IGrouping<TKey, TElement> implements IEnumerable<TElement> , you can use SelectMany to put all the IEnumerables back into one IEnumerable all