Set property in load options from child

I am using Linq for sql to populate my object. I used to use delayed loading, and then repeated access to child objects through my list to force loading. This is not a good solution with the large dataset I have, so now I am setting LoadOptions in my data context to extract it first.

The only problem I encountered is that before I manually load one property at each iteration through my list, I'm not sure how to do it now. This is just a string value.

 info.CreatedByName = info.CreatedBy.Name;

In my data context, I specify the boot 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 the purpose of this property in my boot options? Sort of:

 loadOptions.LoadWith<Info>(info => info.CreatedByName)
+3
2

, LoadOptions . , .

from info in context.Infos
select new InfoContainer
{
    CreatedByName = CreatedBy.Name
}

Info , CreatedBy.Name

public string CreatedByName
{
    get
    {
        return CreatedBy.Name;
    }
}

, CreatedBy , .

+1

, , , CreateBy LoadWith,

var result = from info in context.Infos
             join user in context.Users on info.CreatedById equals user.Id
             select info;

,

+1

Source: https://habr.com/ru/post/1782699/


All Articles