score:1
Accepted answer
That's should what you are looking for :
(i love to use string.IsNullOrEmpty
rather than cmp string.Empty)
_targetHasMissingRatings = _existingRatings.Any(er => string.IsNullOrEmpty(_targetRatings.FirstOrDefault(tr => er.RatingTypeId == tr.RatingTypeId)?.Rating));
score:1
Use IComparable so you can use OrderBy on the entire class or simply compare two instances of the class.
List<RatingDto> ordered = _existingRatings.OrderBy(x => x).ToList();
See code below :
class RatingDto : IComparable<RatingDto>
{
public int RatingTypeId { get; set; }
public string RatingType { get; set; }
public string Rating { get; set; }
public int CompareTo(RatingDto other)
{
if (this.RatingTypeId != other.RatingTypeId)
{
return this.RatingTypeId.CompareTo(other.RatingTypeId);
}
else
{
return this.RatingType.CompareTo(other.RatingType);
}
}
}
Code would look like this :
List<RatingDto> _existingRatings = new List<RatingDto>();
List<RatingDto> _targetRatings = new List<RatingDto>();
Boolean _targetHasMissingRatings = false;
foreach (var existing in _existingRatings)
{
foreach (var target in _targetRatings)
{
if (existing == target)
{
_targetHasMissingRatings = true;
break;
}
}
if (_targetHasMissingRatings == true) break;
}
Source: stackoverflow.com
Related Articles
- Improve comparing between two collections - LINQ? C#
- Match elements between 2 collections with Linq in c#
- LINQ Source Code Available
- Comparing two collections with IEquatable while using only LINQ
- creating Linq to sqlite dbml from DbLinq source code
- Poor performance comparing collections of objects using reflections and Linq Except/Intersect
- Linq statement to select common elements between two collections
- Comparing collections and counting duplicates using LINQ and C#
- Getting differences between collections in LINQ
- C#: Gets unmatched elements between 2 collections with Linq & Lambda
- Comparing performance between custom implemented LINQ methods and the original
- foreach vs LINQ to find difference between collections
- Comparing code prior to LINQ
- source code for LINQ 101 samples
- Comparing Complex Collections using Linq
- LINQ query to find common strings between two collections
- LINQ to entities comparing collections
- Can I use LINQ to compare what is missing, added or updated between two collections
- Add, Update, Remove between collections using Linq
- How to break link between source collection and LINQ result
- c# Linq or code to extract groups from a single list of source data
- IEnumerable.Except() on LINQ doesn't run between ideal source and target lists
- How to improve linq performance with large collections (Code first POCO class)
- LINQ to SQL - Filtering the dataset between two nested collections
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- What is the difference between LINQ ToDictionary and ToLookup
- LINQ Ring: Any() vs Contains() for Huge Collections
- Linq code to select one item
- How to perform Join between multiple tables in LINQ lambda
- C# List Lambda with index, object and DoStuff() / to array
- Custom ordering an Linq query over an observable collection
- Expression.Call GroupBy then Select and Count()?
- Parsing SOAP response with LINQ to XML - how to get nested nodes under parent?
- Group rows in a datatable
- Queryable variable cannot be found in the context
- How do I compare two lists and return 4 categories lists
- How to code an Or extension method
- Changing CSS of dynamically created controls in ASP.Net
- How to perform a LINQ GroupBy, Select, and then Take without performance hit?
- Custom SQL in Entity Framework, results are objects of null
- ObservableCollection from Linq
- How to get occurrence of data and insert it to list
- Help with new override for Except extension method
- Convert a list of objects into a list of new generic objects who contain a list property
- Is it faster to use LINQ to get a row from a List or a foreach loop
- mvc3 and linq - creating a ViewModel
- Equivalent in C# to Haskell's Data.List.Span
- How to dynamically set an expression type within a method
- code that i have to do it through LINQ