Does anyone know of any tweaked version of POCO T4 template that generates interfaces along with classes?
i.e. if I have Movie and Actor entities in .edmx file, I need to get the following classes and interfaces.
interface IMovie
{
string MovieName { get; set; }
ICollection<IActor> Actors { get; set; } //instead of ICollection<Actor>
}
class Movie : IMovie
{
string MovieName { get; set; }
ICollection<IActor> Actors { get; set; } //instead of ICollection<Actor>
}
interface IActor
{
string ActorName { get; set; }
}
class Actor
{
string ActorName { get; set; }
}
Also, just in case I write my own entities, does POCO proxies(I need them for lazy loading) work with the interface declarations as shown above?
You can edit the default T4 template that generates your POCO entities to also generate interfaces. I did this a while back on a project at work. This link covers the jist of how we did it. It’s relatively easy.
Here’s a snippet of our T4 template, might help. We inserted this code into the default T4 template that generates the POCO entities.