- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
Latest commit
33 lines (29 loc) · 1.08 KB
/
Copy pathProgram.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
usingSystem;
usingSystem.Linq;
namespaceCodeFirstExample
{
internalclassProgram
{
staticvoidMain(string[]args)
{
using(vardb=newDBContext.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.Countrycountry=newEntities.Country{Name="United States"};
db.Countries.Add(country);
// Save changes to the database
db.SaveChanges();
// Retrieve and display the countries
varcountries=db.Countries.ToList();
foreach(varcincountries)
{
Console.WriteLine($"Country: {c.Name}");
}
}
}
}
}