If you're using EntityFramework (or any other framework, I guess), the classes auto-generated are marked as partial
, such as the following:
/Project/Data/TelJun2011.cs
namespace Project.Data
{
using System;
using System.Collections.Generic;
public partial class TelJun2011
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
}
/Project/Data/TelJul2011.cs
namespace Project.Data
{
using System;
using System.Collections.Generic;
public partial class TelJul2011
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
}
What partial
means is that you can create another file for the same class. The generated classes don't implement an interface, but you can easily make then implement your custom interface like this:
/Project/Data/ITelMonth.cs
namespace Project.Data
{
public interface ITelMonth
{
int Id { get; set; }
string Name { get; set; }
string Description { get; set; }
}
}
/Project/Data/Partial/TelJun2011.cs
namespace Project.Data
{
public partial class TelJun2011 : ITelMonth { }
}
/Project/Data/Partial/TelJul2011.cs
namespace Project.Data
{
public partial class TelJul2011 : ITelMonth { }
}
And having correctly defined the interfaces, then we can simply do this:
var jul = (from n in TelJul2011s select (ITelMonth)n);
var jun = (from p in TelJun2011s select (ITelMonth)p);
var bimester = jun.Union(jul);
And you can even access the common properties like such:
foreach (var e in bimester)
{
e.Id.Dump();
}