Created
June 28, 2020 15:18
-
-
Save gavilanch/76cb2d275fe74e50f4b8282f504bc09a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace ConsoleApp4 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Begin"); | |
var countries = new List<string>() { "Dominican Republic", "Argentina", "Mexico" }; | |
var stringbuilder = new StringBuilder(); | |
foreach (var countryName in countries) | |
{ | |
var guid = Guid.NewGuid(); | |
var country = new Country() { Id = guid, Name = countryName }; | |
stringbuilder.AppendLine(country.GenerateHasData()); | |
} | |
// Use a breakpoint to examine the result variable and take all of the generated code | |
var result = stringbuilder.ToString(); | |
Console.WriteLine("Fin"); | |
} | |
} | |
public class Country | |
{ | |
public Guid Id { get; set; } | |
public string Name { get; set; } | |
public string GenerateHasData() | |
{ | |
return @$"modelBuilder.Entity<Country>().HasData( | |
new Country(){{ | |
Id = ""{Id}"", | |
Name = ""{Name}"" | |
}} | |
);"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment