N
N
Nikolai Turnaviotov2012-11-03 20:41:56
ASP.NET
Nikolai Turnaviotov, 2012-11-03 20:41:56

How to create a model, controller and views on a table in which all fields are keys?

Greetings.
the database has an automatically created table "webpages_UsersInRoles", where pairs of records are stored - a user ID and a role ID.

CREATE TABLE [dbo].[webpages_UsersInRoles] (
    [UserId] INT NOT NULL,
    [RoleId] INT NOT NULL,
    PRIMARY KEY CLUSTERED ([UserId] ASC, [RoleId] ASC),
    CONSTRAINT [fk_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[UserProfile] ([UserId]),
    CONSTRAINT [fk_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [dbo].[webpages_Roles] ([RoleId])
);

How to correctly create a model for the table so that the controller and views are correctly created - describe in the model that the primary key is composite here - otherwise the studio swears at the absence of a key and the controller with views is not created.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kanaev, 2012-11-04
@Yoh_Asakura

Do you want that in the view you would not have IDs, but, for example, the name of the user and role? If yes, then simply pass the appropriate fields by ID.

J
Jedi_PHP, 2012-11-05
@Jedi_PHP

How do you like this:
1. Create a new entity with your unique ID - pages2userRoles
2. Add a Foreign key there for those things that you want to link - userProfile and webPage, respectively
3. Create a composite index on the label of this entity (for quick search)
4. Pass all calls in the code through this new entity.
those. the idea is that the entity has a PRIMARY KEY column in a separate column (different ORMs often break without such a column).
You can create a composite search index yourself, by hand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question