Home General

LinqPad navigation properties populated show in rich text


clicking link should show the already populated results, but currently even though I manually set nav prop with results.
clicking the link goes and fetches new results which is not what I am wanting, since I am joining tables to get a specific result for nav prop.

Comments

  • What is this type? Where it came from? Are you sure it is not delay loaded?

    Please provide minimum working example.

  • edited March 5

    this is a simple join that filters to only latest of related table record.
    I just connect to database directly with linq and here is the query but the important bit is
    joining to filtered and manually setting with class or method the navigation property does not link to already loaded
    records.

    (
        from record in table
        from relatedRecord in record.navProp.DefaultIfEmpty()
        where record.id == [id]
        orderby relatedRecord.RowId descending
        select new RecordWithRelatedRecord(record, relatedRecord).Record
    ).FirstOrDefault().Dump();
    
    
    public record RecordWithRelatedRecord
    {
        private readonly RecordModel _record;
    
        public RecordModel Record { get => _record; };
    
        public RecordWithRelatedRecord(RecordModel record, RelatedRecordModel relatedRecord)
        {
            if(record != null && relatedRecord != null)
            {
                record.navProp = [relatedRecord];
            }
            _record = record;
        }
    };
    
  • yes pick a model and or table you have because my data is related to business I am working and don't what to share that data for security. but like a said a simple join on data with model that needs its navigation props to populate with data will not produce a navigation property that is already loaded instead the loaded data is wiped out and treated as non-existent.

Sign In or Register to comment.