AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
140 stars 38 forks source link

Expanding into child tables #101

Closed chikwekweg574 closed 3 years ago

chikwekweg574 commented 3 years ago

Firstly, thank you very much for this wonderful library, it's making my life much easier, much appreciated.

One thing I can't seem to be able to do is expand into child tables. I have a suspicion this might be the way my mappings are setup. As an example, I have a query as below: https://localhost:44382/odata/PersonTitles?$expand=Users

The users object is always empty; below is the output:

"@odata.context": "https://localhost:44382/odata/$metadata#PersonTitles(Users())",
    "value": [
        {
            "PersonTitleCode": 1,
            "Description": "Mr.",
            "IsEnabled": true,
            "IsDefault": false,
            "Sequence": 1,
            "Users": []
        }
]

I can see in SQL that only the PersonTitles are queried with no join of any kind to the User(s) table. When I query from child to parent(https://localhost:44382/odata/Users?$expand=PersonTitle)- it expands fine.

My mapping is plain old (for all my models): CreateMap<PersonTitle, PersonTitleDto>();

I am using the 'GetQueryAsync()' method
var personTitles = await _context.PersonTitles.GetQueryAsync(_autoMapper, options, null);

If I drop the library and use EnableQuery removing the need for mapping between the Dtos and the db entities it all works fine.

What could I be missing?

Thanks for your help.

BlaiseD commented 3 years ago

Maybe checkout these examples: Building to Tenant and Tenant to Buildings.

You can always reference the projects locally to see if/where it's blowing up.

If that doesn't clear it up add a sample to a repo we can look at and see it failing.

chikwekweg574 commented 3 years ago

I will try to reference the project locally that might highlight what I am missing. I had gone through the test cases and mappings but I am obviously missing something.