none
modify *.tt template generated by ADO.Net Entity Object generator. RRS feed

  • Question

  • I am trying to modify *.tt template which is generated by default when I run ADO.Net Entity Object generator.

    As a first step I wanted to split Object Context and Entities classes in different physical files.

    eg If I pick two tables while creating my edmx file and when I run my template with edmx input , it should generate 3 physical files.

    First one would be base entity class , which has

    public partial class masterEntities : ObjectContext

        {

            #region Constructors

            #region Partial Methods

            #region ObjectSet Properties

            #region AddTo Methods

        }

    Other two will have entity as the only class and attributes of these classes and whatever we get by default through ADO.Net Entity object generator.

    public partial class spt_fallback_usg : EntityObject

        {

            #region Factory Method

            #region Primitive Properties

       

        }

    I could achieve this by following link

    http://msdn.microsoft.com/en-us/data/gg558520

    Later I plan to add few methods in these *.tt template so as to give more CRUD operation in generated files.

    Now the problem statements

    1.       Using fileManager to create files works but it still creates default *.cs file , which has same name as that of *.tt file ….. can I get rid of this.

    2.       All the *.cs files are created as child files of *.tt template, cannot I move it to a different location by changing *.tt itself.

    3.       If I rename *.tt file to *.T4 to keep standards I maintain in my project, which is usng GAX GAT pattern. Then statement

    <#@ include file="EF.Utility.CS.ttinclude"#> starts giving compilation error and functionality related to fileManager, which helps me creating multiple physical files, does not work.

     

     

    if somebody has tried similar thing and can help me solve these issues !

     


    Arora S
    Wednesday, July 6, 2011 6:24 AM

Answers

  • Hi Arora,


    Welcome to the forum.

    You could use the include  directive to split the normal classes and the contexts.

    Base as I know the template is create files as child files by default, and template is not support dispatch them to other folders.

    I do this by test:

    Find the EF.Utility.CS.ttinclude file: setup vs2010  \Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes

    Open the EL.Utility.CS.ttinclude file

    change:

    var outputPath = Path.GetDirectoryName(_textTransformation.Host.TemplateFile);

    to:

    var outputPath = Path.GetDirectoryName(_textTransformation.Host.TemplateFile)+\\myFolderUnderRoot";

    Then return to the Visual Studio tool Click the Transform All Template on the Solution Explorer window.

    Rebuilt the application and There will be  a error that the includefile does not exist in the project direcotry, we could delete it.

    Then right click the MyFolderUnderRoot folder then select the add existing item, we will find that the includefile is  in the MyFolderUnderRoot folder.

     

    You could dispatch the files by this way, but I support the default action.

    I hope that would be help for you.

     

    Thanks to all the participators.



    David Peng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.




    • Marked as answer by Arora S Monday, July 11, 2011 4:55 AM
    Friday, July 8, 2011 3:09 AM
    Moderator

All replies

  • Hi Arora,


    Welcome to the forum.

    You could use the include  directive to split the normal classes and the contexts.

    Base as I know the template is create files as child files by default, and template is not support dispatch them to other folders.

    I do this by test:

    Find the EF.Utility.CS.ttinclude file: setup vs2010  \Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes

    Open the EL.Utility.CS.ttinclude file

    change:

    var outputPath = Path.GetDirectoryName(_textTransformation.Host.TemplateFile);

    to:

    var outputPath = Path.GetDirectoryName(_textTransformation.Host.TemplateFile)+\\myFolderUnderRoot";

    Then return to the Visual Studio tool Click the Transform All Template on the Solution Explorer window.

    Rebuilt the application and There will be  a error that the includefile does not exist in the project direcotry, we could delete it.

    Then right click the MyFolderUnderRoot folder then select the add existing item, we will find that the includefile is  in the MyFolderUnderRoot folder.

     

    You could dispatch the files by this way, but I support the default action.

    I hope that would be help for you.

     

    Thanks to all the participators.



    David Peng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.




    • Marked as answer by Arora S Monday, July 11, 2011 4:55 AM
    Friday, July 8, 2011 3:09 AM
    Moderator
  • thanks David

    that was useful info , I dint think of looking into Utility.CS.ttinclude file. would try n  explore it more.

    regards


    Arora S
    Monday, July 11, 2011 4:55 AM