I been working on a database in entity framework but encountering some problems.
I have a HotelChain model like this:
[Key]
public int HotelChainID { get; set; }
public string Name { get; set; }
public List<Hotel> Hotels { get; set; }
and a Hotel model:
[Key]
public int HotelID { get; set; }
public string Name { get; set; }
public List<Building> Buildings { get; set; }
public List<Amenities> Amenities { get; set; }
My HotelInitializer class:
Repository.InsertHotel(new Hotel("Brussels", Repository.GetAllBuildings(), Repository.GetAllAmenities()));
Repository.InsertHotel(new Hotel("Paris", Repository.GetAllBuildings(), Repository.GetAllAmenities()));
Repository.InsertHotel(new Hotel("Berlin", Repository.GetAllBuildings(), Repository.GetAllAmenities()));
Repository.InsertHotel(new Hotel("London", Repository.GetAllBuildings(), Repository.GetAllAmenities()));
Repository.InsertHotel(new Hotel("Tenerife", Repository.GetAllBuildings(), Repository.GetAllAmenities()));
Repository.InsertHotel(new Hotel("Amsterdam", Repository.GetAllBuildings(), Repository.GetAllAmenities()));
Repository.InsertHotelChain(new HotelChain("Company Name", Repository.GetAllHotels()));
The problem is that there are double records in my Hotel table in the database, one time with the HotelChain_HotelChainID on null and one time with the HotelChain_HotelChainD on 1.

I'd like to achieve that only the records with the Hotelchain ID on 1 get added to the table. How could I achieve this?
These are my Repository methods:
public static int InsertHotel(Hotel hotel)
{
HotelDbContext context = new HotelDbContext();
context.Hotels.Add(hotel);
context.SaveChanges();
return hotel.HotelID;
}
public static List<Hotel> GetAllHotels()
{
HotelDbContext context = new HotelDbContext();
return context.Hotels.ToList();
}
Thank you for your time!