-
Notifications
You must be signed in to change notification settings - Fork 19
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
Commit with specific entities & BeforeSaveEntity issue #13
Comments
Adding audit trail functionality is very straight forward. I'm not gonna even attempt to debug your code. I don't have time for that. Just looking at it I can see several encapsulation violations, so who knows what's going on there. but I created a feature branch that adds audit trailing to TempHire. As for partial saves. they are no different than full saves. You could just add an optional entities parameter to the existing commit method as demonstrated in the branch. However, I do not recommend doing partial saves within a unit of work. That breaks the whole idea behind the unit of work. The UoW represents a whole change set associated with a task or workflow and the idea is that it gets saved as a whole or rolled back. If you have several independent change sets that you need to save at different times, then you would use multiple UoW instances. Partial saves can be problematic as it is very easy to leave an entity out of the list that's actually required for a successful save. |
Thanks for taking time to reply. I understood my mistakes and thanks for correcting. Audit trail code is working ok when new entity is added since I am assigning CreatedDate & UserCreated during creation, however I am unable to find ways to to send ModifiedDate & UserModified. I appreciate if you can include sample code for utilizing the EntityStateChange event/subscription. Edited: |
I'm not quite following what you are looking for. My sample code in the branch I created does set the modified date on any entity that has such a property during the save on the server. How's that different from what you are asking? |
when we commit() then breeze sends only the modified data e.g if I modify Rate & Quantity I see in the debug only these two fields in the EntityInfo. Since ModifiedDate does not have original value save ignores this field. Am I doing anything wrong? |
That's why we are setting an original value for the modified date on the server. You already had that in your code, too.
|
Since the audit fields (CreatedBy, ModifiedBy, etc.) are defined in AuditEntityBase, they should not also be defined in ExchangeRate or other entity classes. That's what the error is telling you. |
Ok I can exclude to solve this issue but I wont get these AuditEntityBase fields in the client and if I define in partial classes as properties (with some other names) then the Metadatagenerator wont take these properties. Please note I am using DB First. |
I haven't created a DB First EF model in a long long time, so I don't remember if there is a way to properly specify a base class. However, the latest EF when doing DB First actually generates Code First classes if you look at it closely. It no longer generates an ObjectContext and instead generates a DBContext. Although, there's a setting to force it to generate an ObjectContext. My recommendation would be to make sure EF generates Code First code from your DB First model and then abandon DB First and continue to maintain your model in Code First style. DB First and especially ObjectContext are pretty legacy at this point. |
I am getting the following error when I call 'commitEntities' ( extended function to pass specific entities in the save )
If I call 'commit' then savechanges works fine.
Could you please help how I can save specific entities? Below are the code snippets.
I have extended unit-of-work.ts with the below function. Same as 'commit' but added entities parameter.
commitEntities(entities: Entity[]): Promise<Entity[]> {
At server-side, in the DefaultController.cs, I have the below
[HttpPost]
public SaveResult SaveChanges(JObject saveBundle)
{
_unitOfWork._contextProvider.BeforeSaveEntityDelegate = null;
return _unitOfWork.Commit(saveBundle, User.Identity.Name);
}
this is how my save function is written
var changedEntities: Entity[] = this.em.getEntities(typeof BLAgencyLocalCharges, EntityState.Added || EntityState.Modified || EntityState.Deleted)
//.commitEntities(changedEntities)
return this.busyService.busy(this.unitOfWork.commit()).then(() => {
if (suppressConfirmation) return;
this.dialogService.messageBox('Success', 'Successfully saved data!', ['Ok']);
Note:
below is given in the constructor
this.em = unitOfWork.em;
Edited:
BeforeSaveEntity when used with default 'SaveChanges' it did not update the database though I can see the changes the entity during the debug.
Appreciate if you could advise how to achieve Audit trail in Temphire ref app.
The text was updated successfully, but these errors were encountered: