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

Added the possibility to automatically load related tables #4

Closed
wants to merge 16 commits into from

Conversation

petero-dk
Copy link
Contributor

The feature will automatically infer the rowkey if naming conventions are followed, and will automatically handle lazy loaded types.

@petero-dk
Copy link
Contributor Author

petero-dk commented Mar 22, 2018

I am considering a way to improve performance on eagerly loaded tables. As my current implementation would result in a lot of small requests immediately after a large one. I.e for a call with 100 rows there would be 1 + 100 calls.

Any ideas?

@petero-dk
Copy link
Contributor Author

I have recreated the way to load eagerly loaded related tables, it is now resource efficient instead of making one query per related item.

@dei79
Copy link
Member

dei79 commented Mar 24, 2018

I tried to understand what the use case is but could you explain me what you try to achieve with the related table attribute?

@petero-dk
Copy link
Contributor Author

petero-dk commented Mar 25, 2018

Hi @dei79

Sure, the idea is that it makes the library close to a drop-in replacement for entity framework, actually.

Once I have set up the appropriate tables

storageContext.AddAttributeMapperAndCreateTable<Models.Data.Country>();
storageContext.AddAttributeMapperAndCreateTable<Models.Data.Region>();

I can load a single object in my controller like this:
var region = await _context.QueryAsync<Region>(regionPartionKey, regionRowKey, 1);

If the models are created like this:

public class Region {
    public string RegionRowKey {get;set;};
    public string RegionPartitionKey {get;set;};

    public string CountryRowKey {get;set;}

    [RelatedTable("Countries", RowKey: "CountryRowKey")]
   public Country CountryObject {get;set;}
}

The I can reference the related object in the view just like this:

<dt>
    @Html.DisplayNameFor(model => model.Country)
</dt>
<dd>
    @Html.DisplayFor(model => model.Country.Name)
</dd>

That way I do not have to pass extra information to the view (which easily gets confusing if I send a list of objects) and I do not have to keep track of which objects have related tables loaded manually because either they directly have or they will (if I use the Lazy type)

@petero-dk
Copy link
Contributor Author

Sorry for the mess of commits above, I tried to sync the pr with your master. Does my explanation make any sense?

@petero-dk
Copy link
Contributor Author

I will be closing this soon, but I am just cleaning up in all the feature additions and bugfixes I have lying around for this project.

I have tried to separate all individual changes out into different branches and PRs so every change is specific and identifiable.

@dei79
Copy link
Member

dei79 commented Jun 7, 2019

I would like to bring this change in the master but some checks are failing. Would it be ok for you to check this PR again?

@petero-dk
Copy link
Contributor Author

Yes, don't worry about this one, I will refactor it complete into the new master after all the other merges.

@petero-dk
Copy link
Contributor Author

Refactored to #21

@petero-dk petero-dk closed this Oct 20, 2022
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

Successfully merging this pull request may close these issues.

2 participants