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

How to save related data from a service? #37

Closed
vialeda opened this issue May 24, 2018 · 8 comments
Closed

How to save related data from a service? #37

vialeda opened this issue May 24, 2018 · 8 comments

Comments

@vialeda
Copy link

vialeda commented May 24, 2018

Hello, is this possible to save related data without the need of creating a service for each children entities?
Let's say you have this post entity:

  1. Post entity have a collection of PostTranslation
  2. Post entity have a collection of PostField
  3. Then PostField also have a collection of PostFieldTranslation

In order to save it all, I have to create a PostService, PostTranslationService, PostFieldService and a PostFieldTranslationService class. They all have in common an insert method.

Then I have to call them all from PostService:

First => this.Insert(post);
Then => postTranslationService.Insert(post.PostTranslations);
And then => postFieldService.Insert(post.PostFields, postFieldTranslationService);

I wonder if there is a way to tell EntityFramework with URF.Core to insert them all from this.Insert(post).
The version I use from now is 1.0.0-rc1.

Thank you for any advice,

David

@Crazybutch
Copy link

If I understood your question, this could help you (same question i've asked some time ago):
#24

@tonysneed
Copy link
Contributor

Yes I concur with @Crazybutch — you can do graph updates with URF support for my Trackable Entities framework.

@tonysneed
Copy link
Contributor

Let me know if you need further assistance and I’ll re-open.

@vialeda
Copy link
Author

vialeda commented May 25, 2018

Would you give me a quick sample please of how setting a trackable property on objects in the graph?

@vialeda
Copy link
Author

vialeda commented May 25, 2018

Also, does trackable property take care of Update/Insert/Delete?

@tonysneed tonysneed reopened this May 25, 2018
@tonysneed
Copy link
Contributor

If you use the Trackable URF packages and derive your entities from the base Entity class, each object will have a TrackingState property which you can set (usually on the client). This enum has values from Unchanged, Added, Modified, Deleted.

Then in your API all you have to do is call ApplyChanges, followed by SaveChangesAsync.

@vialeda
Copy link
Author

vialeda commented May 26, 2018

Work very well, thank you !! :)

@Domitnator
Copy link
Contributor

Took me a while to figure this out, so for everyone else:

If you are working with OData (like i do) the TrackingState is not automatically added as a property of your model/entity. You have to do this by hand via the ODataConventionModelBuilder:

entitySetConfigurationShipment.EntityType.EnumProperty(x => x.TrackingState);

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