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

feat!: #312 bulk saves #316

Merged
merged 12 commits into from
Sep 11, 2023
Merged

feat!: #312 bulk saves #316

merged 12 commits into from
Sep 11, 2023

Conversation

ascott18
Copy link
Collaborator

@ascott18 ascott18 commented Sep 8, 2023

Breaking: c-select-many-to-many now only performs /save and /delete API calls if the model it is bound to is enabled for autosaves.

Bulk Saves

Bulk saves save all changes to an object graph in one API call and one database transaction. This includes creation, updates, and deletions of entities.

To use bulk saves, you can work with your ViewModel instances on the client much in the same way you would on the server with Entity Framework. Assign objects to reference navigation properties and modify scalar values to perform creates and updates. To perform deletions, you must call model.$remove() on the ViewModel you want to remove, similar how you would call DbSet<>.Remove(model) on the server.

If the client-side Rules/Validation report any errors for any of the models being saved in the operation, an error will be thrown.

On the server, each affected entity is handled through the same standard mechanisms as are used by individual saves or deletes (Behaviors, Data Sources, and Security Attributes), but with a bit of sugar on top:

  • All operations are wrapped in a single database transaction that is rolled back if any individual operation fails.
  • Foreign keys will be fixed up as new items are created, allowing a parent and child record to be created at the same time even when the client has no foreign key to link the two together.

For the response to a bulk save, the server will load and return the root ViewModel that $bulkSave was called upon, using the instance's $params object for the Standard Parameters.

- Perform client validation before bulk saves
- $bulkSave respects $saveMode
- Client validation of FKs that are null locally but will be fixed up by the server
- Cause $bulkSave() and explicit $load() to purge lingering unsaved entities in collections.
@ascott18 ascott18 changed the title wip #312: bulk saves POC feat!: #312 bulk saves Sep 8, 2023
…e-enabled. Looking at the collection item only for deletes was inconsistent.
@ascott18 ascott18 marked this pull request as ready for review September 8, 2023 19:43
@ascott18
Copy link
Collaborator Author

Going to merge now so I can start experimenting on how this feels to use in a project.

@ascott18 ascott18 merged commit 4ca38e6 into dev Sep 11, 2023
19 checks passed
@ascott18 ascott18 deleted the ascott/312 branch September 11, 2023 16:00
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.

1 participant