t4

Access Association Details of NavigationProperty

99封情书 提交于 2019-12-11 08:46:30
问题 I'm creating a C# T4 template to scaffold some classes based on .edmx file, so far so good. What I now need though, is a way to access the name of the columns it connects in the database, through a NavigationProperty. I realized, not long ago, that you can access this information in the .edmx visual designer, under mapping details for an specific NavigationProperty: So basically, if in the T4 template; I already have an instance of the NavigationProperty I want... How can I get the names of

An academic query about T4 templates

折月煮酒 提交于 2019-12-11 08:00:40
问题 Ok, I'm thinking a little ahead here in my current project, so I apologize for how vague this question is going to be. Is it possible in one project of a solution to have a T4 template that references one of the other assemblies in the solution and inspects the exported types of the other assembly and uses their metadata to build up other code? I don't need to reference the types in that assembly directory, I just need to be able to get a list of all of them that derive from a particular base

Two Custom tool s for a single file?

青春壹個敷衍的年華 提交于 2019-12-11 06:45:16
问题 I want to generate some code from my dbml(Linq to Sql) file,the dbml file is placed in many part of my project So I wrote a custom tool for this purpose But the problem is that dbml already has contained MSLinqToSQLGenerator custom tool , So do you know any way to set two custom tools for one file, If no, Let me know your idea about that 回答1: Visual Studio will only support a single "Custom Tool" per file, but you can add a pre-compilation step to run other tools against anything you want.

How can I access other then the “General” attributes of a Entity-Property from a EntityModel within a T4?

为君一笑 提交于 2019-12-11 05:04:50
问题 I am using sort of the following code to get all properties of a entity IList<EdmProperty> list = entity.Properties.Where(p => p.TypeUsage.EdmType is PrimitiveType && p.DeclaringType == entity) Then I iterate through these list, access each Property and read the Property Properties (Yeah, much properties, hope no one gets to confused). While I can easily access the General attributes I don't know how to access the other Properties of the the Entity-Property like Max Length & Fixed Length 回答1:

Creating T4 template file referring SubSonic

折月煮酒 提交于 2019-12-11 04:49:58
问题 I am trying to write T4 template to create wrapper classes for classes created by SubSonic 3 (implementing IActiveRecord). But when I compile my template I get following error: Compiling transformation: Metadata file 'SubSonic.Core' could not be found I'm including SubSonic.Core in my settings file. <#@ assembly name="SubSonic.Core" #> and then importing the namespaces like <#@ import namespace="SubSonic.Schema"#> and <#@ import namespace="SubSonic"#> What I'm doing wrong? Do I need to put

Reflection with T4 Templates

佐手、 提交于 2019-12-11 03:44:48
问题 I have a model class called VideoGame . I need the class to get passed in a t4 template using reflection in this method. MethodInfo[] methodInfos = typeof(type).GetMethods(BindingFlags.Public | BindingFlags.Static); I have the following variables. //passed via powershell file - is a string "VideoGame" var modelName = Model.modelName Type type = modelName.GetType(); I get an error that says: The type or namespace name 'type' could not be found (are you missing a using directive or an assembly

T4 custom code blocks

久未见 提交于 2019-12-11 02:57:44
问题 With T4 can you have custom code blocks, that should not be overwritten at generation? Like PreserveExistingFile but for a block of code in the generated file. I can’t use partial class in my scenario 回答1: There's no way to do this. You should either include unmodifiable code blocks in the template itself, or read them from another file. 来源: https://stackoverflow.com/questions/4546715/t4-custom-code-blocks

Create generic List<T> of T4 generated type

陌路散爱 提交于 2019-12-11 02:47:01
问题 I created simple class using T4 technology. <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".cs" #> using System; <# var properties = new String[]{"P1", "P2", "P3"}; #> public class MyGeneratedClass { <# for(int i = 0; i < 3; i++) { #> private Int32 _<#= properties[i] #> = <#= i #>; public Int32 <#= properties[i] #> { get { return _<#= properties[i] #>; } } <# } #> } then I created an instance of that generated type like this static void Main(String[]

Can the Microsoft TextTransform utility be used standalone?

前提是你 提交于 2019-12-11 02:32:07
问题 I need to use the TextTransform tool in a standalone mode. But it doesn't want to run on machines that don't have Visual Studio installed. Has someone figured out how to do this? 回答1: If you are using this solely on a build machine, then as of Visual Studio 2010, you are licensed to copy the dlls for text templating from the GAC of a Visual Studio installed machine to the build server. We accidentally omitted the filenames from the buildserver.txt file in Visual Studio 2010 RTM, but we've

EF6 and pre-generated views

让人想犯罪 __ 提交于 2019-12-11 01:19:33
问题 I am using EF code first method in my project. Recently I updated EF version of my project to EF 6 using Package Manager Console. All of my entities are inherited from a BaseEntity class as a super class : public abstract class BaseEntity { public virtual int Id { get; set; } States _state; [NotMapped] public States State { get; set;} public enum States { Unchanged, Added, Modified, Deleted } .... } And also I don't add the BaseEntity in my DbContext , the program run without any problem, but