I have a table named CLASS with the Fields
**{BATCH, DEGREE, DEPT, SEM, SECTION, GROUP }**
I has the Following Records
Record1: { 2009 , B.E , CSE , 3Sem , ASec , 1Group }
Record2: { 2009 , B.E , CSE , 3Sem , ASec , 2Group }
Record3: { 2009 , B.E , ECE , 4Sem , ASec , 1Group }
Record4: { 2009 , B.E , ECE , 4Sem , ASec , 2Group }
I Need to Select Distinct Records Ignoring the GROUP and considering only the following
{BATCH, DEGREE, DEPT, SEM, SECTION }
So it should return me the following 2 Distinct Records
Record1: **{ 2009 , B.E , CSE , 3Sem , ASec , 1Group }**
DistinctRecord: 1------------------------(OR)**
Record2: **{ 2009 , B.E , CSE , 3Sem , ASec , 2Group }**
-----(AND)
Record3: **{ 2009 , B.E , ECE , 4Sem , ASec , 1Group }**
DistinctRecord: 2------------------------(OR)
Record4: **{ 2009 , B.E , ECE , 4Sem , ASec , 2Group }**
Now i'm using the following LINQ Query
public static object GetDistictClasses(IQueryable<Class> AllClasses)
{
return (from c in AllClasses
group c by new { c.Batch, c.Degree_ID, c.Specialization_ID, c.CurrentSemester, c.Section_ID } into grp
select new
{
grp.Key.Batch,
grp.Key.Degree_ID,
grp.Key.Specialization_ID,
grp.Key.CurrentSemester,
grp.Key.Section_ID
}).Distinct();
}
But it returns me a Ananymous Type, but i need the Actual Class Type
Could some one Help Me... thank You..
Regrads Pradeep
You can do the following:
return
from c in AllClasses
group c by new
{
c.Batch,
c.Degree_ID,
c.Specialization_ID,
c.CurrentSemester,
c.Section_ID
} into grp
select grp.First();
This takes every first Class
from the given group, thus returns a Entity object instead of a anonymous type.
Lets make it simple - distinct is done on two properties:
also this will return the same object type.
var distinctgroupSubscriptions = groupSubscriptions.GroupBy(item => new { item.User.Id, item.Group.GroupId }).Select(group => group.First()).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With