Is it possible to check whether a list already has an object without considering its inheritance?
For better context, I'm using EF Core to get the list and CQRS to add/update/remove entities. I need to check if the command is equal to any entity in this list, but I can't check any of the Entity properties.
Code example:
public class Entity
{
public Entity()
{
Id = Guid.NewGuid();
}
public Guid Id { get; private set;}
//more properties in the future
}
public class Something : Entity
{
//constructor
public prop1 { get; private set;}
public prop2 { get; private set;}
//add 10 more properties
}
public class CreateSomethingCommand
{
//constructor
public prop1 { get; set;}
public prop2 { get; set;}
//add 10 more properties
}
public async Task Handle(CreateSomethingCommand command)
{
var somethingList = await _somethingRepository.GetSomethingList();
foreach (var item in somethingList)
{
//if (item.CompareProperties(command) is false)
//continue;
await _somethingRepository.Create(item);
}
}
Now I want to check if a list of this Something already has that command added.
The first thing I did was a huge if to check each property, but it is not ideal.
The second thought was an ExistSomething method in the EF core call, but it would take Entity properties into account.
I'm just out of ideas to make it more readable and clean.