I want to compare two list with objects of two different classes. These are the classes:
namespace AngularWebApplication.Models
{
public class AggregationLevelConfigurationPresentation
{
public byte AggregationLevelConfigurationId { get; set; }
public int ProductionOrderId { get; set; }
public string Name { get; set; }
[ ... ]
}
}
public class AggregationLevelConfiguration : IEquatable<AggregationLevelConfiguration>
{
public byte AggregationLevelConfigurationId { get; set; }
public int ProductionOrderId { get; set; }
public string Name { get; set; }
[ ... ]
}
I want to get the elements in presentations
list that are not in currentLevels
:
List presentations; List currentLevels;
List<Models.AggregationLevelConfigurationPresentation> newLevels =
presentations
.Select(l => new { l.AggregationLevelConfigurationId, l.ProductionOrderId })
.Except(currentLevels.Select(l => new { l.AggregationLevelConfigurationId, l.ProductionOrderId }))
.ToList();
But I get the following error when I do the Except
:
Error CS0029 Cannot implicitly convert type
'System.Collections.Generic.List<<anonymous type: byte AggregationLevelConfigurationId, int ProductionOrderId>>' to
'System.Collections.Generic.List<AngularWebApplication.Models.AggregationLevelConfigurationPresentation>'
I think the problem is in the new { l.AggregationLevelConfigurationId, l.ProductionOrderId }
but I don't know how to do the Except
with list of objects from different classes.
I need the objects in presentations
list that they aren't in currentLevels
using AggregationLevelConfigurationId
and ProductionOrderId
as primary key.