This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have two tables in SQL Server 2005, joined using a parent child relationship. Table SystemReport is the parent with the folowing field ID (key), ReportName, etc. Table SystemReportsParameter is the child with the following fields ID (key), ReportKey (FK), Parameter name etc. The tables have a relationship defined in the SQL Server on SysReport.ID -> SysReportParameter.ReportKey. This relationship, and the data, has been confirmed using SQL. The tables are set for Eager load. My first code is as below, which returns an IList<SysReport>. var sars = from sr in uow.SystemReports The returned IList apprears correct, and returns several SysReport objects. Later I need to determine if any SystemReportsParameters exist for a single report. I use the following code. var reps = from s in _sysReps _sysReps is the previously created IList<SysReport> This LINQ returns a single SysReport correctly, however, rep.SystemReportsParameters.Count is always equal to zero. Can you please tell me if I am doing something wrong in my LINQ, or if there is a problem elsewhere. I am using the latest Nightly Build. |
|
|
Does anyone have any ideas of where I might be going wrong with the above code? I have looked at it again, but cannot see anything wrong, but still it does nto show the child records.
|
|
|
Hi Mark, Is that association marked as EagerLoad?
Jeremy |
|
|
Hi Jeremy, I can confirm that EagerLoad is enabled on these tables.
Mark |
|
|
Hi Mark, That will be the cause of it then. If you are using a query with joins we currently dont perform eager loading hence the result you are seeing. If you need these to be conditionally eager loaded then you could use a named aggregate approach which will cause the association to be lazily loaded in the context of this query. Or if you just want to access the specific entities as part of the result set from that specific query you can manually join in the association in your query and then select the entities that way. We do have an item on our backlog to review this behavior in the future as it would be desirable to support eager loading when loading actual entities in this manner.
Jeremy |
|
|
Hi Jeremy, Thanks for the answer, I have now modified my code to take into account your suggestions. Please let me know if you change this behavior in the future. Best regards Mark |
|