SkywardApps / popcorn

Popcorn is a .Net Middleware for your RESTful API that allows your consumers to request exactly as much or as little as they need, with no effort from you.
https://skywardapps.github.io/popcorn/
MIT License
59 stars 19 forks source link

Missing lazy loading tutorial. #4

Closed undiwahn closed 6 years ago

undiwahn commented 7 years ago

Lazy loading is implemented for the entity framework core layer, but there is currently no tutorial or documentation around using it. We need to create one and link to it from DotNetDocumentation.md

jboyer2012 commented 7 years ago

Hi, I'd like to take this. Is there an easy way for me to explore this functionality and see it in action? That would make it easier for me to write it up.

undiwahn commented 7 years ago

Thats fantastic to hear @jboyer2012!

If you grab the solution you can check out the project PopcornCoreTest, and more specifically the tests in ExpanderCoreTests.cs. The Setup method in there configures the lazy loading with the MapEntityFramework, and then we do some limited testing to verify its working. It's only a basic set of tests, but should be enough to walk through the normal usage. And feel free to ask questions or make suggestions!

alexbarbato commented 6 years ago

Hey @jboyer2012 - you still looking into this? Totally cool if not - just going to open it back up if so.

jboyer2012 commented 6 years ago

@alexbarbato Thanks for checking in. I am planning on finishing this up this week. Thanks for your patience!

alexbarbato commented 6 years ago

No worries! Much appreciated

jboyer2012 commented 6 years ago

@undiwahn Just so I understand. The lazy loading is not an extra configuration that you add (with a Lazy Loading method or something similar). The MapEntityFramework call is what provides the lazy loading? Does it work in the same way as EF's lazy loading or are there extra features in Popcorn's implementation?

alexbarbato commented 6 years ago

@jboyer2012 - just going to shoot a quick response until @undiwahn gets a chance to chime in and correct me where I'm wrong or add more, but I think you're totally on the right track.

Using MapEntityFramework I believe allows the user to actually leverage EF's lazy loading features

undiwahn commented 6 years ago

@jboyer2012 MapEntityFramework is indeed the call that 'enables' lazy loading. Essentially, here, the problem is that .net core doesn't yet support lazy loading. (See https://docs.microsoft.com/en-us/ef/core/querying/related-data#lazy-loading) So what we actually do is some fancy footwork behind the scenes to execute Explicit loading (See https://docs.microsoft.com/en-us/ef/core/querying/related-data#explicit-loading) when the property is requested. Thus we've kind of implemented our own version of lazy loading (unfortunately it only works in the context of Popcorn).

For the client, other than providing the necessary context builder (which popcorn will use to load the data from as needed) they shouldn't have to do anything else -- it'll work on anything it recognizes as a navigation property.

Let me know if that isn't clear!

On Fri, Oct 27, 2017 at 3:20 PM, Justin Boyer notifications@github.com wrote:

@undiwahn https://github.com/undiwahn Just so I understand. The lazy loading is not an extra configuration that you add (with a Lazy Loading method or something similar). The MapEntityFramework call is what provides the lazy loading? Does it work in the same way as EF's lazy loading or are there extra features in Popcorn's implementation?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SkywardApps/popcorn/issues/4#issuecomment-340062304, or mute the thread https://github.com/notifications/unsubscribe-auth/AJNm3uc25JqrCOK3wD3o_ws57M9VyGieks5swizsgaJpZM4P3sDw .

-- Nicholas MT Elliott Managing Director Skyward App Company, LLC

jboyer2012 commented 6 years ago

@undiwahn Just created the PR for this. Let me know if you need any changes done.

https://github.com/SkywardApps/popcorn/pull/48