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

Getting AuditLogDetail for properties of complex types. #172

Open
Salalimo opened this issue Sep 9, 2020 · 0 comments
Open

Getting AuditLogDetail for properties of complex types. #172

Salalimo opened this issue Sep 9, 2020 · 0 comments

Comments

@Salalimo
Copy link

Salalimo commented Sep 9, 2020

Hi,

Thanks for making this library available. I have a couple of comments one of which might be a bug, but I might be missing something. The use case is that I have an entity with a complex type.

I had to do this change in CreateComplexTypeLogDetails in ChangeLogDetailsAuditor to be able to get the value:

                     if (GlobalTrackingConfig.DisconnectedContext)
                        origValue = ((DbPropertyValues)complexTypeOrigValue).GetValue<object>(pi.Name);
                    else
                        origValue = complexTypeOrigValue == null ? null : pi.GetValue(complexTypeOrigValue);

This is due to the different types of objects being returned from

        object OriginalValue(string propertyName)   // in DbEntryValuesWrapper

When the DisconnectedContext flag is not set you are returning an object that is the property itself (an object of complex type) that in turn has the has the properties that we are tracking. When the flag is set you are returning a different type of object and the issue is that it does not contain the properties of the complex type. So trying to retrieve the values using reflection by property name does not work.

BTW I tried using the extension method GetPropertyValue by doing => complexTypeOrigValue.GetPropertyValue, but it would go into an infinite loop. Just out of curiosity if that method can be used after its fixed. It is also not being used anywhere so you may consider removing it.

I also needed to do this change
From
Comparator comparator = ComparatorFactory.GetComparator(complexTypeObj);
To
Comparator comparator = ComparatorFactory.GetComparator(pi.GetMethod.ReturnType);

This latter change allows me to record only the properties of the complex type that changed and not all of the properties in the complex object when only one has changed. I understand that someone may consider a change in one of the properties to signify the complex property has changed, so it works for them, but in our usage this is not the case. I just wanted to point it out for your consideration. You may choose to make it an option that some users can configure.

I also made some changes that record the db table names and column names instead of the entity type name and the property names. If you are interested let me know.

Regards.

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

1 participant