I have following class in C# and I'm trying to find a distinct list of items. The list has 24 elements.
public enum DbObjectType
{
Unknown,
Procedure,
Function,
View
}
public class DbObject
{
public string DatabaseName { get; set; }
public string SchemaName { get; set; }
public string ObjectName { get; set; }
public DbObjectType ObjectType { get; set; }
}
I have tow approach and expect to get the same result but I don't.
the first expression returns me the same list (includes duplicates)
var lst1 = from c in DependantObject
group c by new DbObject
{
DatabaseName = c.DatabaseName,
SchemaName = c.SchemaName,
ObjectName = c.ObjectName,
ObjectType = c.ObjectType
} into grp
select grp.First();
lst1 will have 24 items.
but this one returns the desired result.
var lst2 = from c in DependantObject
group c by new
{
DatabaseName = c.DatabaseName,
SchemaName = c.SchemaName,
ObjectName = c.ObjectName,
ObjectType = c.ObjectType
} into grp
select grp.First();
lst2 will have 10 items.
The only difference is the second expression is anonymous but the first one is typed.
I'm interested to understand this behavior.
Thank you!
I believe my question is not duplicate of mentioned one because: What I'm asking here is not how to get the distinct list. I'm asking why Typed and Anonymous data are returning different result.