A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
EntityFramework with multiple value
James
1
Reputation point
Hi
I want to create a Code First EntityFramework Project/Database.
What I want is this (simplfied)
public class Flight
{
public int Id { get; set; }
public string FlightNumber { get; set; }
public Airport Origin { get; set; }
public Airport Destination { get; set; }
}
public class Airport
{
public string IataCode { get; set; }
public string IcaoCode { get; set; }
public string Name { get; set; }
}
public class MyContext : DbContext
{
public DbSet<Airport> Airports { get; set; }
public DbSet<Flight> Flights { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Data Source=(localdb)\ProjectsV13;Initial Catalog=FlightsDB;");
}
}
But this doesn't work, as soon as I have 2 Airports in Flights.
How can I solve this?
I want to have finally 2 Databases with the "IataCode" as Identity (these are always a string with length 3 (ZRH, JFK, LAX).
Should I have a string IataCode in Flights? but how to link them?
Thanks - I am a beginner as you might have noticed :-D
Developer technologies | .NET | Entity Framework Core
Developer technologies | .NET | Entity Framework Core
Sign in to answer