t4

T4 Template Could not load file or assembly 'System.Runtime, Version = 4.2.0.0'

我怕爱的太早我们不能终老 提交于 2019-12-12 20:01:29
问题 So I have a T4 Template I'm trying to run at design-time, but it keeps giving me the following error. Running transformation: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' My Visual Studios solution has 10 projects contained

How can I automate the t4 code generation for SubSonic

北城以北 提交于 2019-12-12 19:14:36
问题 I'm using SubSonic 3 (ActiveRecord mode) to generate the code for my DAL. It uses T4 templates (.tt) files that as soon as you save, generate the code for you. I want to automate this as part of my NANT build, but I can't get this to work. I know that MS provide a tool called TextTransform to generate the code from T4 templates, but in the case of the SubSonic templates this doesn't seem to work - I think the templates make some assumptions about the template being run from within Visual

Is this hack a defined behavior for T4

落花浮王杯 提交于 2019-12-12 17:16:31
问题 I recently set out on an expedition to unit-test a rather complex T4 class. I've arrived at a major breakthough, but I'm afraid the observed behavior may only be coincidental(ie, may break in future versions of Visual Studio) I basically have something like this: MainTemplate.tt: <#@ include file="generator.tt.cs" #> And then in generator.tt.cs I have //<#+ class code { .... } //#> The observed behavior of this is that I can both use the declared classes and such from the T4 template AND

Entity Framework 4.0 Autogenerated Classes not marked as Serializable

爷,独闯天下 提交于 2019-12-12 13:45:24
问题 One strange thing i've got to see in Entity Framework 4.0 V2 Auto Generated Classes(tt) is that the classes are not marked as Serializable. Although they are having DataContract attribute for WCF. Now the problem is, when I store the POCO object into viewstate it throws me an exception saying that the class is not serializable. If I generate the classes without the t4 templates or using the defualt class generating scheme, what i see is that the generated classes are having the Serializable

Entity Framework code first with T4 template

柔情痞子 提交于 2019-12-12 10:43:22
问题 I am going to create code-first view by using a T4 template like the below mentioned article says: Article here But it's causing an run time exception like below. Why's that? My connection string is configured properly in App.config . My application is N-Tier based .So That DbContext driven class is in Data Layer . This is my connection String : <add name="PawLoyalty" connectionString="Server=.;database=PawLoyalty;Trusted_connection=true;pooling=true;MultipleActiveResultSets=True"

Entity Framework Reverse Engineer using Power Tools - No Primary Keys

*爱你&永不变心* 提交于 2019-12-12 05:17:18
问题 I've used the Entity Framework Power Tools Beta 2 to reverse engineer my model classes. However no primary keys have been declared in the data annotations. Is there a way to do this? 回答1: By default, the mapping done via fluent. If you want to change that, you can customize the TT files used to generate the model. Where you would remove it from the mapping.tt and then add the data annotation to entity.tt. Rowan Miller made a great post about that. 来源: https://stackoverflow.com/questions

How define properties as foreign keys in models to MVC Codetemplates generate it as FK

我的梦境 提交于 2019-12-12 03:59:47
问题 I use EFCodefirst. Most of you know, but the following code is part of MVC3 T4 CodeTemplates in Edit.tt And also in Create.tt of AddView: <div class="editor-field"> <# if (property.IsForeignKey) { #> @Html.DropDownList("<#= property.Name #>", String.Empty) <# } else { #> @Html.EditorFor(model => model.<#= property.Name #>) <# } #> @Html.ValidationMessageFor(model => model.<#= property.Name #>) </div> As you see if the CodeTemplates find a property as a FK generate a DropDownList automatically

Call Methods in Transformtext() Method at T4 Preprocessed Template

蹲街弑〆低调 提交于 2019-12-12 03:58:07
问题 I use T4 and Preprocessed Template to generate some codes. So When I add all of the templates directly in .tt file every things is OK like the following: <#@ template language="C#" #> <html><body> <h1>Sales for Previous Month</h2> <table> <# for (int i = 1; i <= 10; i++) { #> <tr><td>Test name <#= i #> </td> <td>Test value <#= i * i #> </td> </tr> <# } #> </table> This report is Company Confidential. </body></html> But I need to grouped codes in some methods and call methods in transformText(

When running TextTransform.exe, how to distinguish between TextTemplatingFilePreprocessor and TextTemplatingFileGenerator?

只谈情不闲聊 提交于 2019-12-11 20:08:23
问题 When running TextTransform.exe, how to distinguish between TextTemplatingFilePreprocessor and TextTemplatingFileGenerator? I cannot use msbuild as most people refer to, so I'm looking for specific thing: how to run TextTemplatingFilePreprocessor in command line for a given TT file. Thank you! 回答1: TextTransform.exe doesn't support preprocessing unfortunately. If you can't use the msbuild tasks (remember you can use msbuild standalone to just do this step inside some other process), then you

DbContext Entity framework Datetime.Now fields

梦想的初衷 提交于 2019-12-11 19:13:46
问题 Have two fields with data type datetime. Added Modified When inserting new record values for both fields must be System.DateTime.Now; but when updating only Modified needs to be changed. I can set StoreGeneratedPattern to Computed and handle Modified field with GETDATE() in database but problem is field Added . My guess is that I have to override SavingChanges() or something similar but don't know how. EDIT : What I have try so far Added another class in my project with fallowing code