Columns connection with an additional column

.net-core c# entity-framework-core

Question

I have such columns in the database:

User
- int Id
- string Name

Flat
- int Id
- string Describe

The flat has a person who manages it and other residents

I think about this solution:

This is the relationship of ManyToMany with an additional column. In this column will be information if he is a managing person

UserFlat
- int UserId
- int FlatId
- bool Creator

Will this be the right approach?

How should I implement it exactly?

Is it directly as a ManyToMany relation or as a manually created and managed table?

The blockage is that users can belong to only one apartment (in the future, the manager will be able to belong to several apartments), but the remaining people can belong to only one apartment

Or is it a completely different and better solution?

1
0
9/19/2018 9:25:40 AM

Popular Answer

If a user can have only one flat and a flat can have only one manager, you don't need a separate table. This should suffice and will work even if one User can be manager of multiple flats:

    User
- int Id
- string Name
- int FlatId > FK to a Flat

Flat
- int Id
- string Describe
- int ManagerId > FK to a User
1
9/19/2018 9:31:37 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow