Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3667476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:00:20+00:00 2026-05-19T02:00:20+00:00

Does anyone know of any tweaked version of POCO T4 template that generates interfaces

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:00:21+00:00Added an answer on May 19, 2026 at 2:00 am

    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.

    <#
        GenerationEnvironment.Clear();
        string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);    
        string outputPath = Path.Combine(templateDirectory + @"..\..\Models\Interfaces\Repositories\IEntitiesContext.cs");
    #>
    
    using System;
    using System.Data.Objects;
    using Models.DataModels;
    
    namespace Interfaces.Repositories
    {
        #pragma warning disable 1591
        public interface IEntitiesContext : IDisposable
        {
        <#
            region.Begin("ObjectSet Properties", 2);
    
            foreach (EntitySet entitySet in container.BaseEntitySets.OfType<EntitySet>())
            {
    #>
            IObjectSet<<#=code.Escape(entitySet.ElementType)#>> <#=code.Escape(entitySet)#> { get; }
    <#
            }
            region.End();
    
            region.Begin("Function Imports", 2);
    
            foreach (EdmFunction edmFunction in container.FunctionImports)
            {
                var parameters = FunctionImportParameter.Create(edmFunction.Parameters, code, ef);
                string paramList = String.Join(", ", parameters.Select(p => p.FunctionParameterType + " " + p.FunctionParameterName).ToArray());
                if (edmFunction.ReturnParameter == null)
                {
                    continue;
                }
                string returnTypeElement = code.Escape(ef.GetElementType(edmFunction.ReturnParameter.TypeUsage));
    
    #>
        ObjectResult<<#=returnTypeElement#>> <#=code.Escape(edmFunction)#>(<#=paramList#>);
    <#
            }
    
            region.End();
    #>
    
            int SaveChanges();
            ObjectContextOptions ContextOptions { get; }
            System.Data.Common.DbConnection Connection { get; }
            ObjectSet<T> CreateObjectSet<T>() where T : class;
        }
        #pragma warning restore 1591
    }
    <#
            System.IO.File.WriteAllText(outputPath, GenerationEnvironment.ToString());
            GenerationEnvironment.Clear();
    #>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know any site or book that presents problems like python challenge ,
does anyone know any sort of app that lets users visit a page on
Does anyone know of any websites, or (preferably) downloadable packages that you can use
Does anyone know of any way to overcome NotSupportedException? I have a method against
Does anyone know any as3 libraries that allow you to scale, rotate, skew, etc..
Does anyone know any other way that I can use (beside of @strpos()) to
Does anyone know any way from the command line or with subclipse that I
Does anyone know any cache providers for .NET that support streaming data directly in/out
does anyone know any tool for 'code generation' using MVC2? I know that ASP
Does anyone know any web service that I can retrieve information about soccer games?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.