Aug 03, 2020 11:33 AM|PatriceSc|LINK
The problem is that you told EF that fotoblock.guid is the "primary key" while it is actually the "foreign key". So yij sun suggestion is to add a true primary key column into your database to fix this.
Also you shouldn't be able to enter two row with the same ID in the Transport table.
When EF is loading the 2nrd row, it sees it has already a row from the same table with the same primary key value and so this 2nd row is likely just ignored as the "primary key" is supposed to be unique.
To understand pk vs fk see perhaps https://www.dotnettricks.com/learn/sqlserver/difference-between-primary-key-and-foreign-key#:~:text=Primary%20key%20uniquely%20identify%20a,primary%20key%20in%20another%20table.&text=By%20default%2C%20Primary%20key%20is,the%20sequence%20of%20clustered%20index.
Edit: also the pk is liekly not well defined on the db side else it should block creating two rows with the same pk which is what you have done for both Transport and fotoblock. See also :
- https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property?view=sql-server-ver15 (allows
to autonumbering int id columns)
You can stiull use a Guid for your primary column if you prefer (except that you'll have to assign a value for newly inserted rows yourself).