我正在尝试使用Entity Framework更新连接表,但是我没有达到远程,因为我收到了转换错误:
无法将类型转换为System.Data.Objects.DataClasses.EntityCollection
因此,当我尝试将Passenger对象传递给Flight实体时,它无法进行转换。
这是表结构:
Flight table - FlightID PK
Passenger Table - Passenger ID PK
Passenger_Flight table - PassengerID PK,FlightID PK
if (isValid())
{
Passenger cpass = ((Passenger)passengerIDComboBox.SelectedItem);
Flight newflight = new Flight {
Rego = planeRegoComboBox.SelectedItem.ToString(),
DepartureTime = departureDateTimePicker.Value,
ArrivalTime = arrivalDateTimePicker.Value,
DepartureLocation = departureLocationComboBox.GetItemText(departureLocationComboBox.SelectedItem),
ArrivalLocation = arrivalLocationComboBox.GetItemText(arrivalLocationComboBox.SelectedItem),
Passengers = cpass // this is the problem. Cannot convert type to System.Data.Objects.DataClasses.EntityCollection
};
flightEntity.Flights.AddObject(newflight);
Validate();
//flightEntity.Passengers.AddObject(pass);
flightEntity.SaveChanges();
refreshItems();
}
提前致谢。我希望我提供了足够的信息。此问题与https://stackoverflow.com/questions/19087747/an-object-with-a-temporary-entitykey-value-cannot-be-attached-to-an-object-cont
相关联