c# - Type safety of indexed columns in an in-memory database -
Root of the problem: I want to design a database entry member indexing API, for which the model definition does not require repetition and maintenance.
A fair level of security of type.
Dry Out-Explanation: I have a basic memory database of people in the table, the full name of each person and the key to their favorite celebrity.
Public class IMDB {public dictionary & lt; Int, person & gt; People; } Public class person {public string first name; Public string last name; Public int favorites celebrity id; } Now the celebrities want to be able to find their fans quickly through favorite celebrity ID . An index is clear, and thinking for the future, I created this interface:
public class IMDB {public dictionary & lt; Int, person & gt; People; Private dictionary & lt; Object, dictionary & lt; int, int & gt; & Gt; _rowContents; Private dictionary & lt; Object, dictionary & lt; Int, list & lt; Int & gt; & Gt; & Gt; _rowIndex; // Returns the id field in the given row Public Intuit related AID (Int ARID, Object field) {...} // The ID of each field returns the key given in the field with the public list & lt; Int & gt; Public Zero SetRelatedID (int rowID, int key, object field) {...}} Public category individual {public enum}, maintains the setter index for the field of {0} IDRelatedIDs (int key, object field) {...} IndexedFields {FavoriteCelebrityID} public string first name; Public string last name; } I have seen the benefit:
- Fixed type protection at the API level, from one side to
object passing
In any new tables, it is easy to create an NM for the indexed key.
No duplicated field name in the person model. But now I need to index the string last name , so I can find families. This is where I got stuck my best The idea is to implement one third of index methods for each data type:
public class IMDB {... public int id referenced id (integer line id, object field) {... } Public List & Lefthine Print; Integer & gt; {...} Public Zero SetRelatedID (int rowID, int key, object field) {...} Public string IDRelatedString (int rowID, object field) {...} public list & lt; Int & gt; ; String RelievedIds (String Key, Object Field) {...} Public Zero Serialized String (Ent Row ID, String Key, Object Field) {...}} Public Category Individuals {Public Enem Index IDEd {Preferred ID} Public Enum Indicated Strings {LastLime} public string first name; } but can now accidentally put in IndexedStrings entry IDRelatedID , which can only be identified on runtime.
Is there a way to expose a member index API that:
- Do not require recurrence in model definitions?
- Maintains a fair level of security of type?
Due to the concerns of efficiency, I want to be very careful of proxy objects, but the resources that explain how to create an efficient proxy, that would be great! I got a good solution using generic:
public class IMDB {/ div>
field) {...}} People of the public class {//} "new indexmember ()" to get started before the first access , Or // init on startup (some other manifest has been used previously) // Public Static Index Numbers for Less Verticality & lt; Int & gt; favoriteCelebrityID; Public stable indexmember & lt; String & gt; last name; Public string first; } Public Class IndexMember & lt; T & gt; {// ...} If I can apply it then I am very satisfied with it, but any improvement or alternative solution is always welcome.
Comments
Post a Comment