EntityFramework-Plus icon indicating copy to clipboard operation
EntityFramework-Plus copied to clipboard

Audit: resolving FK-Property Dislayname and relate Parent/Child

Open eismue opened this issue 9 years ago • 5 comments

Hello and good day,

recently I found your audit solution and I'm virtual attired. But these points bothers me and must be asked:

  • is there a way to resolve an userfriendly name from a foreign key property instead of writing numeric foreign keys value in old/newvalue? DefaultConfiguration.Format works only on scalar values. background: we need values for endusers not developers/dba's.
  • when is dbo.AuditProperties.RelationName filled? Within our tests this field always is null, although 1:n relations has been updated. We are searching for a solution to audit changes in master/detail scenarios, where the history for an enduser must be prepared and this in the context af a master-object (for example: opening an user-page within a web-app and showing change-history to editors. Scalar fields like lastname etc. could be changed and details in related 1:n tables could be changed. On the basis of the logentries in AuditEntities/AuditProperties there seems no way to easily query a changes made on a user-object and its related detail-data. Any hint? Something for a future relase? No way?

Thanks for an answer and of course your work.

eismue avatar Oct 20 '16 13:10 eismue

Hello @eismue ,

is there a way to resolve an userfriendly name from a foreign key property instead of writing numeric foreign keys value in old/newvalue?

I'm not sure to understand this question, can you give me a small example of the actual result and wished result.

when is dbo.AuditProperties.RelationName filled

It's filled for EF5 && EF6 when a new relation is added or removed. If you are using EF Core, it's still not used but could be used in the future.

there seems no way to easily query a changes made on a user-object and its related detail-data

You are right, that's a great suggestion. We will make some research about this suggestion but I don't think this could be implemented before version 2.0.

Please let me know more about your first question and if you are using EF Core, we will improve our comment according to your answers.

zzzprojects avatar Oct 20 '16 14:10 zzzprojects

Hello and thanks for the quick answer and sorry for the late reply...

Point 1: ... is there a way to resolve an userfriendly name from a foreign key property instead of writing numeric foreign keys value in old/newvalue?... I'm not sure to understand this question, can you give me a small example of the actual result and wished result. .... Lets say there is a users-table (Id, Lastname, Firstname,) and an m:n relation for language skills (languages-table: Id, LanguageName,...). One user can have many language skills. The table to map between users and languages is not surprisingly shaped like Id, UserId, LanguageId. Problem: only the keys will be auited (UserId, LanguageId). What I need: insteed of the pure scalar int/bigint-value I want for languages the value from the languages-table LanguageName-field. This is important, because and enduser without any database skills must see what has been changed. Resolving the language-name at query-time is to expensive and cannot work, if an entity has been deleted. I hope I could clearify my suit.

Point 2: ... when is dbo.AuditProperties.RelationName filled ... We are using EF6. Sorry for not hinting at this. And in our first testing scenarios we only were updating. So I understand why this field was empty.

Thank you.

eismue avatar Nov 03 '16 07:11 eismue

Hello @eismue ,

We implemented in the v1.4.10 an AuditDisplay DataAnnotation.

You can see more how to implement here: Issue #67

Let me know if this solution or a similar solution is what you are looking for.

My guess is this solution doesn't fully fill your requirement since you will need to set the DisplayName at runtime (the name change with language value by example).

Best Regards,

Jonathan

zzzprojects avatar Nov 07 '16 16:11 zzzprojects

Hi and thanks. The AuditDisplay/DataAnnotation unfortunately cannot help at this. Thats because Displayname can only change the description, but not the saved value that must be dynamically evaluated from a navigation-property, if its an foreign key that changed. And: we are using edmx-models, so data-annotations are not applicable :)

However, have a nice day.

eismue avatar Nov 25 '16 06:11 eismue

Hi, I also have the same problem and haven't yet found any complete solution. Simplified code:

class Machine { int FamilyId {get; set} }
class MachineFamily { int FamilyId {get; set} string Name {get; set} }

When I change the FamilyId field of Machine object the audit contains changes from id to id (for example from 1 to 5). I would like it to display OldValue= "SomeNameOfFamily1", NewValue="SomeOtherNameOfFamily5".

I tried two approaches: A) Specifying AuditEntryPropertyFactory, but even if I explicitly set NewValue it was not used B) Specifying formatter in EntityValueFormatters. This solution is very close, but in the end, formatter receives only the value of the property and not the entity.

Could you point me to some other idea? Did anybody implement such feature successfully?

krajek avatar Mar 09 '18 13:03 krajek