You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lets Assume we have Entity with two relation objects.
int Id_ObjA;
ObjA ObjA
int Id_ObjB
ObjB ObjB
public class ObjA{
int Id;
string NameA;
}
public class ObjB{
int Id;
string NameB;
}
We want to compose history for user but we don't want to show message like 'ObjA changed from Id 1 to 2' but 'ObjA changed from Hello to Hi'
But we cannot distinguish between ObjA and B. All we have in AuditLogDetails is PropertyName: Id_ObjA, OriginalValue: 1, NewValue: 2.
I used a reflection mechanism to find the type of such relation object by spliiting property name Id_ObjA by undersore sign and then used second item as type name, search assembly for such type, pass type with id to generic method that returned proper object from dbContext (but not casted, plain object so still do not have any info about properties inside at compilation time) and then try to retirieve value of the property I wanted (In fact created interface with one method returning string, implemented it on all entites to have one point to retrieve such historic user friendly description of given entity).
And that is quite complex and for newcomer to project hard to understand. And also easily breakable (Just change foreign key from Id_ObjA to ObjAId and you have to modify splitting the name of property from LogDetails)
But with full name of relations Objects Type this procedure can be much easier and more reliable as you don't have to rely on splitting a property name that can be changed by mistake.
However if you intend to somehow support relations in more advanced way (for example track Id's but during retrievieng from Db put there actual object like EF is doing with relations) then I guess you can completly ignore this suggestion ;)
The text was updated successfully, but these errors were encountered:
Easier retrieval of relation objects properties.
Lets Assume we have Entity with two relation objects.
We want to compose history for user but we don't want to show message like 'ObjA changed from Id 1 to 2' but 'ObjA changed from Hello to Hi'
But we cannot distinguish between ObjA and B. All we have in AuditLogDetails is PropertyName: Id_ObjA, OriginalValue: 1, NewValue: 2.
I used a reflection mechanism to find the type of such relation object by spliiting property name Id_ObjA by undersore sign and then used second item as type name, search assembly for such type, pass type with id to generic method that returned proper object from dbContext (but not casted, plain object so still do not have any info about properties inside at compilation time) and then try to retirieve value of the property I wanted (In fact created interface with one method returning string, implemented it on all entites to have one point to retrieve such historic user friendly description of given entity).
And that is quite complex and for newcomer to project hard to understand. And also easily breakable (Just change foreign key from Id_ObjA to ObjAId and you have to modify splitting the name of property from LogDetails)
But with full name of relations Objects Type this procedure can be much easier and more reliable as you don't have to rely on splitting a property name that can be changed by mistake.
However if you intend to somehow support relations in more advanced way (for example track Id's but during retrievieng from Db put there actual object like EF is doing with relations) then I guess you can completly ignore this suggestion ;)
The text was updated successfully, but these errors were encountered: