I have the below tables where the StationAvailableMoves.StationID and StationAvailableMoves.AvailableNextStationID both have relationships on the Station.ID column.
I am using this to control a process from from station object to station object where on station can have multiple routes.
When I then import those tables into the Entity Framework model I get the below circular reference table.
I am then trying to load the data in the below DTO
Imports System.Runtime.Serialization
Namespace Models
<DataContract()>
Public Class Stations
<DataMember()>
Public Property ID As Int32
<DataMember()>
Public Property Name As String
<DataMember()>
Public Property BullName As String
<DataMember()>
Public Property StationMoves As IList(Of Stations)
End Class
End Namespace
While I can load the data into the primitives types, with the below LINQ query, I am not sure how the then load the child objects which are coming over in the call.
Using db As New StockTrackingEntities
Dim var = (From s In db.Stations.Where(Function(w) w.BUID.Equals(buID))
Select New Stations With {.ID = s.ID,
.Name = s.Name,
.BullName = s.BullName}).ToList
End Using
Can I do this in a single LINQ statement or do I need to For Each over the collection and load it manually?
EDIT:
I have tried the below statement (which might be rubbish) and while it compiles it generates a runtime exception
Dim var = (From s In db.Stations.Where(Function(w) w.BUID.Equals(buID))
Select New Stations With {.ID = s.ID,
.Name = s.Name,
.BullName = s.BullName,
.StationMoves = From m In s.Station1
Select New Stations With {.ID = m.ID,
.Name = m.Name,
.BullName = m.BullName}}).ToList
Exception
Removing the ToList from the above query to prevent the exception it actually evaluates it the blow object.