-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
33 lines (29 loc) · 1.08 KB
/
Program.cs
File metadata and controls
33 lines (29 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Linq;
namespace CodeFirstExample
{
internal class Program
{
static void Main(string[] args)
{
using (var db = new DBContext.WorldCountries())
{
// Ensure the database is created always
db.Database.Delete();
db.Database.Create(); // This will create the database if it doesn't exist
// db.Database.CreateIfNotExists(); // Use this if you want to create the database only if it doesn't exist
// Create a new country
Entities.Country country = new Entities.Country { Name = "United States" };
db.Countries.Add(country);
// Save changes to the database
db.SaveChanges();
// Retrieve and display the countries
var countries = db.Countries.ToList();
foreach (var c in countries)
{
Console.WriteLine($"Country: {c.Name}");
}
}
}
}
}