I’m using Linq to sql to populate my object. Previously, I was using deferred loading and then iterating through my list accessing the child objects to force loading. This isn’t a very good solution with the large data set I have so I am now setting the LoadOptions in my data context to grab it all initially.
The one problem I’ve run into is that before I was manually loading a single property on each iteration through my list and I’m not sure how to accomplish this now. It’s just a simple string value.
info.CreatedByName = info.CreatedBy.Name;
In my data context, I’m specifying my load options as such:
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<Info>(info => info.Owner);
loadOptions.LoadWith<Info>(info => info.CreatedBy);
Is there a way to specify assignment of this property in my load options? Something like:
loadOptions.LoadWith<Info>(info => info.CreatedByName)
I don’t think that you can use LoadOptions in this way. You could use a projection container class, if you don’t need to perform object tracking, and explicitally set the property upon construction.
You could add a partial class for Info and add a property that refers to CreatedBy.Name
That would assume that the CreatedBy is loaded, or lazy load it if its not populated.