Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Created June 28, 2020 15:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavilanch/76cb2d275fe74e50f4b8282f504bc09a to your computer and use it in GitHub Desktop.
Save gavilanch/76cb2d275fe74e50f4b8282f504bc09a to your computer and use it in GitHub Desktop.
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