-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlightDbContext.cs
48 lines (43 loc) · 1.39 KB
/
FlightDbContext.cs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace FlightChallenge
{
public class FlightDbContext : DbContext
{
public DbSet<Route> Routes { get; set; }
public DbSet<Flight> Flights { get; set; }
public DbSet<Subscription> Subscriptions { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"data source=ELES;initial catalog=FlightChallenge;Trusted_Connection=True;MultipleActiveResultSets=true;Encrypt=false");
}
}
[Index("DepartureDate", "OriginCityId", "DestinationCityId")]
public class Route
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public int RouteId { get; set; }
public int OriginCityId { get; set; }
public int DestinationCityId { get; set; }
public DateOnly DepartureDate { get; set; }
}
public class Flight
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public int FlightId { get; set; }
public int RouteId { get; set; }
[ForeignKey("RouteId")]
public Route Route { get; set; }
public DateTime DepartureTime { get; set; }
public DateTime ArrivalTime { get; set; }
public int AirlineId { get; set; }
}
[Keyless]
public class Subscription
{
public int AgencyId { get; set; }
public int OriginCityId { get; set; }
public int DestinationCityId { get; set; }
}
}