Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/VS2012/EF_CodeFirst_RemovePK/console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace EF_CodeFirst_RemovePK
{
class Program
{
{
static int Main(string[] args)
{
try
Expand Down Expand Up @@ -44,7 +44,7 @@ static int Main(string[] args)
//Note: I can call dataProvider.InitDatabase() but the issue is, in the case the DB already exists because InitDatabase has SetDatabaseInitializer() that will create the DB tables.
// We have to set the DB Connection factory first and then depending if the DB exists or not, let the user decide if he/she wants to recreate the tables.
dataProvider.InitConnectionFactory();

//Creates the EF Context based on the connection string
EFCustomContext context = new EFCustomContext(connectionString);

Expand All @@ -53,7 +53,7 @@ static int Main(string[] args)
{
Console.WriteLine("Do you want to remove the existing DB? (Y/N) \nBy removing the DB you will autogenerate your new tables, if aplicable.");
if (Console.ReadKey(false).Key == ConsoleKey.Y)
{
{
context.Database.Delete();
dataProvider.InitDatabase();
context.Database.Create();
Expand All @@ -71,7 +71,11 @@ static int Main(string[] args)
personService.InsertPerson(new Person() { FirstName = "Jorge" });

//Select the person and display it
Console.WriteLine("\n\nResult from DB Query:\n\n" + personService.GetAllPersons().FirstOrDefault().FirstName);
Console.WriteLine("\n\nResult from DB Query:\n");
foreach (var person in personService.GetAllPersons())
{
Console.WriteLine("{0,-3} {1,-20} {2}", person.Id, person.FirstName, person.LastUpdated);
}
Console.ReadLine();
return 1;
}
Expand Down