score:1
Accepted answer
I have managed to build by StructuralEqualityComparer<T>
myself since .NET does not supports this with the reasons mentioned on dasblinkenlight's answer, thanks dasblinkenlight.
private class StructuralEqualityComparer<T> : EqualityComparer<T> where T : class
{
public override bool Equals(T x, T y)
{
return typeof(T).GetProperties()
.All(pro => pro.GetValue(x).Equals(pro.GetValue(y)));
}
public override int GetHashCode(T obj)
{
int hashCode = typeof(T).GetProperties()
.Aggregate(0, (current, pro) =>
current ^ pro.GetValue(obj).GetHashCode());
return hashCode.GetHashCode();
}
}
Source: stackoverflow.com
Related Query
- Look for built-in class like StructuralEqualityComparer<T> with generic version
- Create a C# Generic class for repeated code
- My Enumerable class does not work with Linq statements like .where in c#
- How do I build Expression Call for Any Method with generic parameter
- C# - Error CS1928: Checking for list element with derived class
- Look for words in strings with LINQ
- LINQ expression with generic class properties
- Is anything wrong with this linq insert? Seems like a lot of SQL for simple operation
- Stubbing Code for Test With Linq Expressions and Lambdas
- Requirements for collection class to be used with LINQ
- generic method to get linq result to datatable for select new with multiple selects
- Implementing IComparable<T> Interface for a generic class to compare type T
- With a generic repository for entity framework, how do I query entities which implement a specific interface?
- How can I write generic query in asp .net mvc for 3 different tables in db context with LINQ?
- Query with linq for balanced values of a class
- Code clarity for converting generic list?
- Check a List of a class for a specific variable with LINQ
- Converting Generic List of object to defined collection class with Lambda and C#
- filter list <object> with list<string> and look for a match in c#
- source code for LINQ 101 samples
- ForEach loop with Lambda expression in Razor code MVC 5 For List<T>
- generic class for linq / lambda expression
- Displaying Html.ListBoxFor for association class with one additional property
- Building Dynamic Where Clause with Generic filtering for field types
- Optimized code for Insert and Update in one method with LINQ?
- linq function for use with generic repository entity in where clause
- Generic type class for EF Core join results
- EF Core: The LINQ expression could not be translated for a nested List with Generic StartsWith() Expression
- Generic search with expression trees gives System.NullReferenceException for nullable fields
- Union 2 lists with additional content change for ID that occurs in both source lists
More Query from same tag
- How to form a Method based syntax in Linq Entity Framework
- Add a if statement condition to a Linq statement
- Is LINQ's Enumerable.Take method a good equivalent of SQL's TOP in terms of speed?
- Generic Linq ordering function?
- LINQ query for this scenario
- .NET service OData return anonymous type from LINQ query
- Use IEnumerable.Sum to subtract in LINQ
- comparing 2 inconsistent xml files using linq
- SQLite and LINQ: find all objects that have a sub list with all ids present in a supplied list of IDs
- Update query on temporary table in Linq
- NHibernate left join with linq
- NHibernate Linq and DistinctRootEntity
- How to include two object inside the same select on Linq MVC5
- Get most common data from CSV File with LINQ
- Difference between value of first and last record Linq
- LINQ to XML optional element query
- use LINQ to query a list
- Select rows by criteria to fill a list
- How to use generic interface as generic constraint?
- Comparing two collections of objects
- Linq GroupBy Clause
- Updating a Data Bound GridView on Button Click
- Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Linq.IQueryable<>'
- searching using linq
- Linq Find Item by Primary Key and display Name(that lives in a different table)
- Converting Sql Query to LinQ with Reverse SQL Command
- Powershell Equivalent of Linq Statement
- Linq - Include and filter - nested collections
- linq query with list
- Intersect two lists and return the similarity with the preserved order of the original first string value