I have a PrivilegeGroup
table, a Privileges
table and a link
table because the PrivilegeGroup
table and the Privileges
table is a many to many relationship. I am thinking about load all contents of PrivilegeGroup
table and Privilege
table into memory from data开发者_如何学Pythonbase at beginning when application started.
I want to save them in a form easily to look up. Usually we will look up the PrivilegeCode
via GroupId
.
Which structure is good for this purpose? array of list? dictionary?
It sounds like you want to be able to look up PrivelegeCode by the GroupId and don't need any other data? If that is the case then you could use a Dictionary<GroupIdDataType, PrivelegeCodeDataType>
which should make the lookups easy.
As for loading them all at once on starting the application, I guess it just depends on if changes to this data while the application is running should have any effect on the program without having to restart it.
How about
Dictionary<GroupIdType, HashSet<PrivilegeCodeType>>
This way you can quickly get the HashSet of privileges by GroupId, and do a quick test against the HashSet to check if the privilege exists.
I'll suggest you to keep the data in the instance of DataTable class.
精彩评论