Created
August 23, 2016 20:04
-
-
Save Zabaa/d7c7617793abdeaf6c56aa3ecd7c9774 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#@ template language="C#" #> | |
<#@ output extension=".sql" #> | |
<#@ assembly name="$(ProjectDir)bin\Debug\SiepaczeKoduSample.Infrastructure.dll" #> | |
<#@ import namespace="System.Collections.Generic" #> | |
<#@ import namespace="SiepaczeKoduSample.Infrastructure" #> | |
<# | |
IList<Dictionary> dictionary = TemplateHelper.GetDictionary(@"C:\Users\Zaba\Pictures\SiepaczeKodu\Dictionary.csv"); | |
#> | |
<#foreach (var item in dictionary) | |
{ | |
#> | |
IF NOT EXISTS (SELECT TOP 1 * FROM dbo.Dictionary WHERE [key] = '<#= item.Key #>') | |
INSERT INTO dbo.Dictionary ([key], [value], [description]) VALUES ( '<#= item.Key #>', '<#= item.Value #>', '<#= item.Description #>') | |
GO | |
<# | |
} | |
#> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TemplateHelper | |
{ | |
public static IList<Dictionary> GetDictionary(string filePath) | |
{ | |
IList<Dictionary> dictionary; | |
var csvConfiguration = new CsvConfiguration | |
{ | |
Encoding = Encoding.UTF8, | |
CultureInfo = new System.Globalization.CultureInfo("pl-PL") | |
}; | |
using (StreamReader reader = File.OpenText(filePath)) | |
{ | |
using(var csv = new CsvReader(reader, csvConfiguration)) | |
{ | |
dictionary = csv.GetRecords<Dictionary>().ToList(); | |
} | |
} | |
return dictionary; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment