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

Easier retrieval of relation objects properties #116

Open
bilal-fazlani opened this issue Jun 26, 2016 · 1 comment
Open

Easier retrieval of relation objects properties #116

bilal-fazlani opened this issue Jun 26, 2016 · 1 comment

Comments

@bilal-fazlani
Copy link
Owner

Easier retrieval of relation objects properties.

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 ;)

@bilal-fazlani
Copy link
Owner Author

@ChewieWookie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant