재우니의 블로그


Dapper.SimpleCRUD 대해서 visual studio 2015 로 T4 기능을 사용해서 MODEL 을 GENERATION 할 수 있습니다.


먼저 패키지 관리자 콘솔을 통해서 아래 처럼 실행합니다.


PM> Install-Package Dapper.SimpleCRUD.ModelGenerator


설치 하면, Models 폴더에 아래 ModelGenerator.tt 파일이 생성됩니다. 이는 text template 약자입니다.


실행하기 전에 먼저 web.config 에 연결자 이름을 기재합니다.


web.config


 <connectionStrings>
    <add name="EntityGeneration"
         providerName="System.Data.SqlClient"
         connectionString="Password=xxxxxx;Persist Security Info=True;User ID=shimpark;Initial Catalog=MySolution;Data Source=." />
  </connectionStrings>


그 다음 tt 파일을 열어서 연결자 이름을 할당하고 원하는 namepsace 를 기재 후 ctrl + S 누릅니다.


ModelGenerator.tt


// Settings
 ConnectionStringName = "EntityGeneration"; // Uses last connection string in config if not specified
 ConfigPath = @""; //Looks in current project for web.config or app.config by default. This overrides to a relative path - useful for seperate class library projects.
 Namespace = "WebApplication3.Models";
 ClassPrefix = "";
 ClassSuffix = "";
 IncludeViews = true;
 IncludeRelationships = true;
 ExcludeTablePrefixes = new string[]{"aspnet_","webpages_"};



tt 파일 다음 트리에 ModelGenerator.cs 이 생성됩니다. 빌드할 필요없이 단지 tt 파일에 저장만 누르면 됩니다.