Something very simple that should work is not working for me, I have case like this
var equipment = new Equipment(); // This has Id column PK, INT and Identity
context.Equipment.Add(equipment);
var software = new EquipmentSoftware(); // This has primary key EquipmentId which is actually the Id of equipment table
software.EquipmentId = equipment.Id;
context.EquipmentSoftware.Add(software);
context.SaveChanges();
Now ideally this should work, it should create record of equipment software based on the id generated for equipment.
But it is not doing this and giving me primary key violation error for equipment software table because it is trying to enter EquipmentId - 0 in equipment software table, that means it is not taking the equipment id of the equipment that is generated
Any idea?
Edit
This all code is under transaction. So I want it all to get inserted in one go, that is why I do not want to use context.SaveChanges() to save equipment first and then use the Id, that way it will definitely work I know because then the record will be created for equipment in database and I don't want that partial inserts but all in one go.