I am trying to implement the WorldWideImporters sample database in an ASP.NET MVC application.
Everything is working using just a test SQL database with a single table "Persons".
However when using the WorldWideImporters every table is sorted into categories: Application.Cities and Application.Countries or Sales.Orders and Sales.Customers.
Where I would normally write my model like this:
public class DataContext : DbContext
{
public DataContext(DbContextOptions<DataContext> options) : base(options)
{ }
public DbSet<Person> Persons { get; set; }
}
public class Person
{
[Key]
public int PersonID { get; set; }
[Required]
public string FirstName { get; set; }
}
And my controller like this:
public class PeronsController : Controller
{
private readonly DataContext _context;
public PeronsController(DataContext context)
{
_context = context;
}
// GET: Orders
public async Task<IActionResult> Index()
{
return View(await _context.Persons.ToListAsync());
}
}
I am no longer able when the database tables are sorted with a dot for instance Sales.Orders does not work in the above model and controllers. How can I correctly model and controller for this sample database?
This is what I would like to do:
public class ShopContext : DbContext
{
public ShopContext(DbContextOptions<ShopContext> options) : base(options)
{ }
public DbSet<City> Application.Cities { get; set; }
}
public class City
{
[Key]
public int CityID { get; set; }
[Required]
public string CityName { get; set; }
}