t4

Switch from Entity Framework Database First to Code First

断了今生、忘了曾经 提交于 2019-12-06 04:07:08
问题 Our Solution is currently based on Entity Framework Database First. We have a T4 Template that generates repository classes from the EDMX. We are reviewing our planned approach for releasing changes, especially Database changes. If we continue with Database first, then we will need to separately generate scripts to change the development and other databases. It seems that with Code First, we simply change the model and that generates scripts to change the various databases. This seems more

Custom Output File Path For T4 Template

こ雲淡風輕ζ 提交于 2019-12-06 03:54:34
I am finding it really difficult to use t4 templates with a non-standard directory structure. I am using links inside my csproj file, which seems to be at the root of the problem. I have it working, however, VS automatically makes a change which breaks things. I've have the following directory structure: /source + MyLib.cs /generate /MyLib + MyLib.tt + MyLib.A.t4 // included by MyLib.tt + MyLib.B.t4 // included by MyLib.tt + MyLib.C.t4 // included by MyLib.tt /build_examples /vs + MyLib.csproj + MyLib.sln MyLib.csproj looks like this: <?xml version="1.0" encoding="utf-8"?> <Project

T4 Templates and Visual Studio Item Templates

﹥>﹥吖頭↗ 提交于 2019-12-06 03:23:30
Is it possible to create a Visual Studio item template that generates from a T4 template? My google-fu does not seem powerful enough to yield an answer! Yes, you need to use GAX for that. It has a (rather limited implementation of) custom T4 host that allows you to use T4 as a template language. Yes you can, actually ASP.NET MVC uses this approach when creating View item from Controller item All the Best Muse VSExtensions 来源: https://stackoverflow.com/questions/805979/t4-templates-and-visual-studio-item-templates

Dynamically change data annotation in dynamic data project

点点圈 提交于 2019-12-05 23:27:15
问题 I have come across a scenerio that to customize DataAnnotations in Dynamic Data Web Application. This is the scenerio: [Display(Name="DispName")] public string DName{get;set;} Instead of hardcoding Name="DispName" for Display DataAnnotation, I want to fetch some value from DataBase and fit int the Name attribute. like: [Display(Name=SomeValueFromDB)] public string DName{get;set;} Is there any way to show the Name attribute of Display DataAnnotation from database instead of hardcoding its

How to use DbContext in T4 template?

和自甴很熟 提交于 2019-12-05 20:53:21
I want to generate some code with a T4 Template using EntityFramework. I created a T4 Template in the same Assembly as my currently working EF6 DbContext: <#@ template language="C#" hostspecific="true" debug="True" #> <#@ assembly name="$(SolutionDir)\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll" #> <#@ assembly name="$(TargetPath)" #> <#@ import namespace="Conwell.Administration.Data.Entities" #> <# using (var db = new KassenautomatEntities()) { #> //Hello World <# } #> When I run it, I get the following execption: Running transformation: System.InvalidOperationException: The

EF4: Get the linked column names from NavigationProperty of an EDMX

久未见 提交于 2019-12-05 19:11:50
问题 I am generating POCOs (lets say they are subclasses of MyEntityObject ) by using a T4 template from an EDMX file. I have 3 entities, e.g.: MyTable1 (PrimaryKey: MyTable1ID) MyTable2 (PrimaryKey: MyTable2ID) MyTable3 (PrimaryKey: MyTable3ID) These entities have the following relations: MyTable1.MyTable1ID <=> MyTable2.MyTable1ID (MyTable1ID is the foreign key to MyTable1) MyTable2.MyTable2ID <=> MyTable3.MyTable2ID (MyTable2ID is the foreign key to MyTable2) Or in another view: MyTable1 <=

Is there a way to get Visual Studio to run “Transform All Templates” upon a successful build?

匆匆过客 提交于 2019-12-05 18:23:49
I have a T4 template that geneates helpert code based on other code that is declared within my project. Because of this, I have to build my project before I run "Transform All Templates". Is it possible to have "Transform All Templates" run as a post-build-event upon a successful build? I've not really tried it myself but I think you want to look into this . You should be able to modify your project files to achieve what you want. An easier solution may be to modify your templates A LA the T4 MVC templates so that they automatically mark themselves as dirty on build (check the docs page and

Finding a property is Primary Key in POCO Template t4 generator

十年热恋 提交于 2019-12-05 18:03:50
问题 I'm using the POCO t4 template generator that comes with VS 2012. I made few changes to include the Entity.Name, but I'm not able to figure out the primary key. public string EntityClassOpening(EntityType entity) { return string.Format( CultureInfo.InvariantCulture, "{0} {1}partial class {2}{3}<{4},{5}>{6}", Accessibility.ForType(entity), _code.SpaceAfter(_code.AbstractOption(entity)), _code.Escape(entity), ": EntityBase", entity.Name, entity.Name, _code.StringBefore(" ", _typeMapper

How to Exclude a T4 Template from a NuGet Package

前提是你 提交于 2019-12-05 16:52:45
I'm creating a NuGet package the provides a client for my WebAPI project by reflecting over the ApiController s and creating classes for each one with methods that correspond to the actions defined on the controller. Unfortunately the .tt file is being included in the content folder when I run nuget.exe pack Client.csproj . I've tried creating a .nuspec file with a <files> directive, but I can't seem to exclude the file by itself. Does anyone know how to force the package to exclude the T4 template? The project structure is roughly: Website/ Controllers/ UserController.cs ... Client/ Client.tt

In T4 code generation, how can I grab a type from a referenced assembly?

吃可爱长大的小学妹 提交于 2019-12-05 15:09:56
Since T4 runs outside of the context of a project, I don't have access to the current assembly or other assemblies. How can I register access to a referenced assembly, then grab a type from it? I am guessing you want to access an assembly your building in your project. What I've done in the sample code below is adding a project to my solution called TestLib which I build to the folder .\T4Libs in the solution directory. TestLib has a class called MyHelper which holds a magic number. FYI VS2010 SP1 added the great feature in that it no longer locks the imported assemblies so that's a good