I am attempting to use code first and the fluent API to create an object that holds two different entities from the same table. In other words, a transfer object holds a reference to two different tank objects--one is the source and the other the destination.
However, when I use the following code I get an Exception stating that "The referential relationship will result in a cyclical reference that is not allowed."
modelBuilder.Entity<Transfer>()
.HasRequired<Tank>(t => t.Source)
.WithMany(t => t.OutboundTransfers);
modelBuilder.Entity<Transfer>()
.HasRequired<Tank>(t => t.Destination)
.WithMany(t => t.InboundTransfers);
My best guess is that it thinks I am pointing both keys to the same Tank? Any idea how I can accomplish this?
EDIT: Found the answer as adding .WillCascadeOnDelete(false) from Entity Framework Code First - two Foreign Keys from same table