What I should have asked before.,
What do you want to do after you sort them?
The answer to this can have a big impact on the potential solution.
If the answer is something like I need to display a list of dates where you only need dates in order. If so, you do not need to combine the two lists, you can get a sequence of only ordered dates and use them, for example.
var orderedDates = networks.Select(n => n.NetworkingDate) .Union(privateNetworks.Select(n => n.DateCreation)) .OrderBy(date => date);
If the answer is: I need to display a list of links showing a date that refers to the identifier of the object, and something to identify the type of object, then you could leave with something very similar to the above, with the Anonymous object.
var orderedDates = networks.Select(n => new {Date = n.NetworkingDate, Id = n.NetWorkingId, NetworkType = n.GetType().Name}) .Union(privateNetworks.Select(n => new {Date = n.DateCreation, Id = n.PrivateNetWorkingId, NetworkType = n.GetType().Name})) .OrderBy(n => n.Date);
However, if the answer is: I need to send the Shutdown () command to the 10 oldest networks, then you really need a polymorphic solution , where you have one type that you can call Shutdown() , which will solve the specific Shutdown() method for the types, which you use.
A polymorphic solution to use only if the khellang answer user does n't work for you
From the comment to another answer
@BinaryWorrier I chose this answer because I already have entries in the databases, so if I want to add a new interface, how will I work with entries already saved before adding the interface?
I find it hard to believe that your ORM will not allow you to add an interface to an entity class, and not - somehow - mark this interface and / or its member so that they are ignored by ORM.
However, if you cannot add a new interface or base class, you can still do it polymorphically.
Add an interface, add a class that implements the interface for each of your network classes ( Abstractor classes), then convert the network classes to Abstractor classes by adding them to the List<INetwork> and sorting this list.
public interface INetwork { DateTime? Date { get; } } public class PrivateNetworkAbstractor :INetwork { private PrivateNetwork network; public PrivateNetworkAbstractor(PrivateNetwork network) { this.network = network; } public DateTime? Date { get { return network.DateCreation; } } } public class NetworkingAbstractor : INetwork { private Networking networking; public NetworkingAbstractor(Networking networking) { this.networking = networking; } public DateTime? Date { get { return networking.NetWorkingDate; } } } ... public IEnumerable<INetwork> MergenSort(IEnumerable<Networking> generalNetWorks, IEnumerable<PrivateNetwork> privateNetWorks) { return generalNetWorks.Select(n => new NetworkingAbstractor(n)).Cast<INetwork>() .Union(privateNetWorks.Select(n => new PrivateNetworkAbstractor(n)).Cast<INetwork>()) .OrderBy(n=> n.Date); }