I am using LINQ as the ORM in a web application project using VS2010. I defined the ER in the SQL database and simply dragged and dropped the database tables into the ORM. The Transfer table has 4 relationships to the Hospital table with 4 different columns. One of the column is FK, int, not null. The other three are FK, int, null. In the DBML the Transfer class has 4 associations to Hospital class. The association with the required Transfer.Hospital (FK, int, not null) has the following properties.
Cardinality: OneToMany
Child Property: True
Access: Public
Inheritance Modifier: (None)
Name = Transfers1
Parent Property
Access: Public
Inheritance Modifier: (None)
Name: HospitalSrcOrDest
Participating Properties: Hospital.HospitalID -> Transfer.Hospital
Unique: False
The View Model used by the view page has a Transfer property of Transfer type. The Model.Transfer.Hospital always has an integer value. However, the Model.Transfer.HospitalSrcOrDest in following page script is always null. Shouldn’t HospitalName be automatically retrieved via Hospital_Transfer1 association? Thanks.
<%: Model.Transfer.HospitalSrcOrDest != null ? Model.Transfer.HospitalSrcOrDest.HospitalName : string.Empty%>
I modified my repository constructor, but it doesn’t make any difference.
As I understand it, LINQ uses Eager Loading as default (http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/10/06/linq-to-sql-deferred-loading-lazy-load.aspx). In my View Model the Transfer is passed in by the Controller. Should I add a HospitalSrcOrDest property to the View Model and load the value by navigating the association.