Click here to Skip to main content
15,903,030 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Everyone,

I have written the code as follows:In group by clause i want to group by CellId.
SQL
if (zteBbhRecords.Count > 0)
                           {
                               zteBbhRecords.Cast<IZteBbh>().Select(zteBbh => (zteBbh.CombinedMaster as ICombinedMaster).CellId.ToString()).GroupBy((zteBbhEntity.CombinedMaster as ICombinedMaster).CellId).Where(items => items.Count() > 1).Select(item => item.Key).Distinct().ToArray();
                           }




I am getting the error as follows:
Error	19	The type arguments for method 'System.Linq.Enumerable.GroupBy<TSource,TKey>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TKey>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.	F:\Quantum India\New Projects\Kaizen\Code\Kaizen.Application\Kaizen.Application.2G\Kaizen.Application.2G.DataManagers\ZteBbhDataManager.cs	218	33	Kaizen.Application.Kaizen2G.DataManagers


Please kindly assist .
Thanks
Harshal
Posted
Comments
[no name] 16-May-14 10:07am    
Anybody can guide me .Please

Thanks
Harshal
karthik Udhayakumar 17-May-14 1:37am    
which line throws this error ..can you insert a breakpoint and let me know?
Abhishek Bose 17-May-14 14:20pm    
Hi Karthy,<br>
 <br>
I guess it is pretty clear that the group by operator is causing the exception.

1 solution

Hi R Harshal,

The Group By operator cannot be used as the way you are using it. Simply putting the cast doesnot work (This is what you are doing here -
GroupBy((zteBbhEntity.CombinedMaster as ICombinedMaster).CellId)
Rather it should be something like
GroupBy(cells =>(zteBbhEntity.CombinedMaster as ICombinedMaster).CellId)
. Group By has 8 Overloads and for deep insight you can refer the following link - http://msmvps.com/blogs/jon_skeet/archive/2011/01/01/reimplementing-linq-to-objects-part-21-groupby.aspx[^]
 
Share this answer
 
Comments
[no name] 22-May-14 4:01am    
Thank you Friend .
Thanks A lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900