Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated example for Includes #564

Open
Reddevildragg opened this issue Apr 6, 2022 · 5 comments
Open

Updated example for Includes #564

Reddevildragg opened this issue Apr 6, 2022 · 5 comments

Comments

@Reddevildragg
Copy link

Reddevildragg commented Apr 6, 2022

Quick question around is there an updated example for the Includes function?

The documentation shows the function taking 1 parameter (which i assume is a query for the table you want to connect into

var books = db.Query("Books")
    .Include(db.Query("Authors")) // Assumes that the Books table have a `AuthorId` column
    .Get()

However version 2.3.7 the include function appears to take a minimum of 2 parameters for relationName and query, but also optional for foreignkey, localKey and is many.

Is there an example of how to pull this together under the new parameters.

What i have tried to far is as followed:

db.Query("User").Where("User.Id", index).Include("Project",db.Query("Projects"), "ProjectId", "Id", false).Get<User>();

Which runs but then when running the "Project" field within the User Class remains as Null, not sure if i have the request wrong or if the mapping is into a class is not working as i thought it may be. For this case my User Class has the following:

public int ProjectId { get; set; }
public Project Project { get; set; }

Project Id gets mapped, but not project

Thanks for any help.

@Reddevildragg
Copy link
Author

So upon playing around a bit it looks like the above is the correct way to write the include.

However it only works if i dont pass a type into the Get function to cast it from anything other than a dynamic. Looking into the code because my class does not inhearit both IDynamicMetaObjectProvider and IDictionary<string, object> the handleIncludes function just returns the results when executing.

Is there a work around for casting with the nested classes or is this currently a limitation of the system, i can work around with if so, but just checking im not missing anything ovbious on how i have set up the systems

@ahmad-moussawi
Copy link
Contributor

No unfortunately the include functionality is limited by the Dynamic types for now, I didn't find an easy way to achieve that for non dynamic types at the moment.

@Reddevildragg
Copy link
Author

No worries, I can work around it with a couple of requests, was just wondering if i had missed anything ovbious.

If i get time may have a play around with the source code and see if can think of an elegant solution, but cant promise anything :)

Thanks for the quick response

@codebyevisla
Copy link

codebyevisla commented Nov 14, 2023

@Reddevildragg would you mind sharing an example please? A few of us here #308 are struggling to find an efficient way to cast it when it seems buried in dictionaries.

@trishmun
Copy link

trishmun commented Feb 1, 2024

@Reddevildragg would you mind sharing an example please? A few of us here #308 are struggling to find an efficient way to cast it when it seems buried in dictionaries.

Yes, please share an example, haven't solved it yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants