mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-27 10:40:59 +08:00
Updated Cascade Saving (markdown)
@@ -1,12 +1,10 @@
|
|||||||
[中文](%e8%81%94%e7%ba%a7%e4%bf%9d%e5%ad%98) | **English**
|
[中文](%e8%81%94%e7%ba%a7%e4%bf%9d%e5%ad%98) | **English**
|
||||||
|
|
||||||
It is found that n to 1 is not suitable for cascade preservation. Save the type information when saving the topic? Personally, I think the bottom-up saving function is too uncontrollable. FreeSQL does not support bottom-up saving at present. Therefore, we will only talk about OneToOne/OneToMany/ManyToMany cascade save. As for manytoone cascade storage, manual processing is used, which is more safe and controllable.
|
In practice, it has been found that N-to-1 is not suitable for cascading saving, for example: when saving the Topic, do you also save the Category information? The function of saving from bottom to top is too uncontrollable. Therefore, the following will only discuss OneToOne/OneToMany/ManyToMany cascading saves.
|
||||||
|
|
||||||
## Savemany save manually
|
## Savemany save manually
|
||||||
|
|
||||||
Save completely, compare the existing data in the table, and calculate the execution of addition, modification and deletion.
|
Completely save the specified navigation attributes, compare the existing data in the table, and calculate the execution of adding, modifying, and deleting.
|
||||||
|
|
||||||
Recursive saving of navigation attributes is unsafe and uncontrollable. It is not a technical problem, but for security reasons. It provides a way to save navigation attributes manually and completely.
|
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
var repo = fsql.GetRepository<Type>();
|
var repo = fsql.GetRepository<Type>();
|
||||||
@@ -24,14 +22,14 @@ repo.SaveMany(type, "Topics"); ////Manually and completely save topics
|
|||||||
|
|
||||||
-SaveMany only supports onetomany and manytomany navigation properties
|
-SaveMany only supports onetomany and manytomany navigation properties
|
||||||
-Save only topics, not downward recursive tracing
|
-Save only topics, not downward recursive tracing
|
||||||
-When topics is empty, delete all table data of topics existing in type, and confirm?
|
-When Topics is Empty, delete all table data of Topics that exist for type
|
||||||
-The manytomany mechanism is to completely compare and save the intermediate table, and only append the external table without updating
|
-ManyToMany compares and saves the intermediate table completely, and only appends and does not update the external table
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
-This table song
|
-This table Song
|
||||||
-External table tag
|
-External table Tag
|
||||||
-Intermediate table Songtag
|
-Intermediate table SongTag
|
||||||
|
|
||||||
## EnableCascadeSave warehouse cascade save
|
## EnableCascadeSave warehouse cascade save
|
||||||
|
|
||||||
@@ -48,9 +46,9 @@ repo. DbContextOptions. EnableCascadeSave = true; // Manual opening required
|
|||||||
repo. Insert(type);
|
repo. Insert(type);
|
||||||
```
|
```
|
||||||
|
|
||||||
-Do not delete the existing data in the topics sub table. Are you sure?
|
-Do not delete data that already exists in the Topics subtable
|
||||||
-When the topics attribute is empty, do not do anything. Confirm?
|
-When the Topics attribute is Empty, no action is taken
|
||||||
-When you save topics, you will also save the subordinate collection properties of topics \ [0 -.. \]. Go down to 18 layers and confirm?
|
-When saving Topics, the subordinate set properties of Topics \ [0-.. \] will also be saved, down 18 layers
|
||||||
|
|
||||||
>For example, in the [type] table, there is set attribute [article] below and set attribute [comment] below [article].
|
>For example, in the [type] table, there is set attribute [article] below and set attribute [comment] below [article].
|
||||||
|
|
||||||
@@ -62,10 +60,6 @@ Compare and save the intermediate table completely, compare the existing data of
|
|||||||
|
|
||||||
Append external tables, only append without updating.
|
Append external tables, only append without updating.
|
||||||
|
|
||||||
-This table song
|
|
||||||
-External table tag
|
|
||||||
-Intermediate table Songtag
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Test 1: append and save OneToMany
|
Test 1: append and save OneToMany
|
||||||
|
|||||||
Reference in New Issue
Block a user