locked
Importing Stored Procedures as Datafunctions using Entity Framework t4 template - DBContext Generator RRS feed

  • Question

  • User-1872987150 posted

    Hi,

       I'm working in ASP.NET MVC5 web application in N Tier architecture. We will be using EntityFramework 6 as ORM technology for Database transactions. We will not be using EDMX designer for designing and generating boiler plate codes for CRUD operation. DBContext generator as t4 template has been utilized for POCO generation which will be mapped to the DB tables with out conflicts. Now we need to generate POCO for stored procedures being utilized in the database. While digging in to some blogs, it has been observed that DBContext doesn't support POCO generation for  stored procedures. We are focusing on t4 template creation which needs to generate POCO code and data functions for sp'swith complex return type which will be pretty much needful for us to invoke it in dependent layers . Any help will be greatly appreciated.

    Thanks,

    Chendhil Veal.

    Sunday, May 17, 2015 2:56 PM

All replies

  • User1938476581 posted

    Hi,

    You can resolve the first problem by locating the following block of code in the TT file and replacing it with the updated version listed below.

    Original:

    <#  if (container.FunctionImports.Any())  {  #>  using System.Data.Objects;  using System.Data.Objects.DataClasses;  using System.Linq;  <#  }  #>

    Updated:

    <#  if (container.FunctionImports.Any())  {  #>  using System.Data.Entity.Core.Objects;  using System.Data.Entity.Core.Objects.DataClasses;  using System.Linq;  <#  }  #>

    For more information, please refer to the document:

    http://www.dotnetbits.com/entity-framework-6-t4-templates/

    Wednesday, May 27, 2015 9:19 AM