2

I am trying to query the comments that has relationship with request table like this below

public class Request
{
    public Guid Id { get; set; }
    [Column(TypeName = "jsonb")]
    public Correspondence Correspondence { get; set; }
    public MasterSection MasterSection { get; set; }
    public RequestStatus RequestStatus { get; set; }
    public RequestStage RequestStage { get; set; }
    public RequestType RequestType { get; set; }
}

and here is my class for correspondence class below

 public class Comment
{
    public string Text { get; set; }
    public string CommentBy { get; set; }
    public DateTime CreatedAt { get; set; }
}
public class Correspondence
{
    public List<Comment> Comments { get; set; } = new List<Comment>();
}

and here is my linq query to get the results

 public IQueryable<Request> GetAllRequests()
 {
        return _dbContext.Requests.Include(i =>i.RequestStage)                                 
                                  .Include(i =>i.RequestType)
                                  .Include(i =>i.MasterSection)
                                  .Include(i=> i.Correspondence).ThenInclude(i=> i.Comments);

  }

but getting an error like Lambda expression used inside Include is not valid. with out including correspondence, the above query is working is fine but when i included the correspondence getting above error.

Is there any other way to get all those related data along with correspondence for the requests

I am using EF core 3.0

Could any one have any idea why i am getting this error and any idea how to overcome this error that would be very grateful to me.

Thanks in advance

sample data

enter image description here

10
  • Instead of .ThenInclude have you tried chaining .Include("Correspondence.Comments")? Commented Dec 18, 2019 at 19:15
  • i tries getting the same error that i was mentioned in the question return _dbContext.Requests.Include(i => i.RequestStage) .Include(i => i.RequestType) .Include(i => i.MasterSection) .Include(i => i.Correspondence) .Include("Correspondence.Comment") Commented Dec 18, 2019 at 19:18
  • 1
    Can use share the mapping class of this classes? Commented Dec 18, 2019 at 19:19
  • i already shared above in the question about request object with the correspondence class and i am using code first approach, please let me know if you need more info Commented Dec 18, 2019 at 19:24
  • @LuttiCoelho please let me know if you need anymore info Commented Dec 18, 2019 at 19:35

1 Answer 1

1

As mentioned in comments of Question, correspondence is a blob field in the request table itself you don't need to use Include. Include is for loading related entities.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.