c# - NHibnerate data design recommendations -


While doing some research in the mapping of one-to-one relationship, I've got some statements that ask me some questions. Database design decisions.

Actually, I have some institutions like:

People, contact, parent

Contact and parents are both people, The guardian can not be both or both.

Each of these three entities is in the database design that comes with me, and all the three tables have a primary ID (person identity). From database design perspective, it seems that there is a well-generalized and properly executable way to represent the database and its relationships (at least for me).

At this point, I use a mapping of the C # classes and the most natural mapping approach to mapping the NHibnerate to represent these entities. I have other options (one-by-one, one -to-many, etc.) require that I add one or more unnecessary FK to tables. By browsing through the NHibernate documentation, I stumbled on the following statement:

This feature is often useful only for legacy data models, we recommend less table than classes and Although a subtle domain model, as explained later, later in a single hierarchy, it is useful to switch between legacy mapping strategies.

My question is:

a) Do I violate this principal? B) If so, how can I better design this system?

Is this the statement that I should put all the persons / contact / parent areas on a table (with many tapable areas)? Or am I missing something like that?

Since this is a rare opportunity, from which I can design tables / sections with scratch, I want to get it right. Thanks in advance for the help!

EDIT: How do I intend to design the above database to work:

The basic idea is that each person gets a record in the person's table. The presence / absence of records in the respective tables determines whether a person is a parent, contact, etc. ... This seems to apply to a relationship-> and allows quick questions / joining (a) Shared primary ID will be a PK compiled in each table).

EDIT: Thanks to the people for help I did not really think quite well enough when I designed this system, I'm going to something like the solutions suggested by Jamie Idea; Hlgem I found all the answers useful, the primary key result shared in everything is the result of some problems with the object model on the C # side. > Some of these depend on how you want to query that data. If you want to be able to play the role of a role easily looking at specific details for a role, then it has a roles table to see all the roles of a person, how many roles you add later, Nevertheless, it is necessary to be included in only two tables. Otherwise, you will have to be included in each special table (left is added if they are not present) to see just what a person's roles are. Not very good for performance.

There are a lot of these types of relationships in our database and we have a person table with ID, a roles table with ID and the role id and role type table in which there is a look for roles and then Special tables have information for specific roles, such as sales representatives or sales targets, each table has its own ID and each table (the lookup table is short). IK) contains the ID from the person table which is set in the form of a foreign key (I believe there is such a small thing as an unnecessary foreign key, the conversation is not correct, when you should get a bad news, I can not remember now.)

Now you can still keep foreign key relationships from the parent table by using PK only in the person table with the PK and the PK of the specialty table with both I I advise against In any event, if you do not set an FK in the person table, then data is dependent on data integrity issues. I like to use the surrogate key and thus always set my key on each table. This has prevented many new designs for a long time. If you want to maintain a one-to-one relationship, then you need a simple unique index on the field. The table runs from one to one to one-to-many and whatever you do is drop the index. If you were also using it as your PK, then you need a new PK and you have to change all code referenced to PK. Adding a new PK to the table with 150,000,000 records, not fun work.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -