English 中文(简体)
Linq DBML Mapping a Table With A Primary Key That Spans 2 Columns
原标题:

I have three tables: Login, LoginRoles and Roles. Login joins to LoginRoles and LoginRoles joins to Roles. LoginRoles is a many-to-many table, and I want to constrain the columns as being unique TOGETHER.

LoginRoles: MemberId (int), RoleId(int)

This is similar to the aspnet_UsersInRoles table in the default membership database: Table 3.2

I set the primary key for this table as both of the columns.

When dragging the table into the DBML diagram I can not see this primary key represented in the diagram and I get the warning (and other similar ones):

Warning 1 DBML1062: The Type attribute LoginRole of the Association element Login_LoginRole of the Type element Login does not have a primary key. No code will be generated for the association. 0 0

Any ideas on how to make it recognise the Primary Key?

最佳回答

You are trying to use 2 value keys as the primary key for the table. This should really be done in the SQL Table Definition. If you right click inside the table definition you should be able to access the Indexes/Keys option. In there you are able to specify the 2 columns you want to use as the primary key.

Alternatively you could run a small SQL Script, something like:

ALTER TABLE LoginRoles
ADD CONSTRAINT pk_MemberRole PRIMARY KEY (MemberID,RoleID)

Once you have updated your table you need to delete/re-drop your table back onto the DBML designer and the code will update.

问题回答

暂无回答




相关问题
Matrix to Represent a Triangle in Screen Space

So i have a set of four points in 3D Space. P1 [0, 0, 0] P2 [128, 0, 0] P3 [0, 128, 0] P4 [128, 128, 0] Which I m then projecting orthographically to the screen effectively giving me two ...

Using LINQ To SQL with multiple database tables

I have an employee class with as follows: public class Employee { public string FirstName { get; set; } public string LastName { get; set; } public string UserName { get; set; } ...

Mapping points from Euclician 2-space onto a Poincare disc

For some reason it seems that everyone writing webpages about Poincare discs is only concerned with how to represent lines and measure distances. I d like to morph a collection of 2D points (as ...

Fluent NHibernate, varbinary(max) and SQLite

I have a varbinary field in my sql server database that needs to be varbinary(max). I create my database with NHibernate and I use Fluent Nhibernate for my mappings. I also use SQLite for my unit ...

Javascript redirect

I am working with javascript and here is what I am trying to do: 1. Send a get request which looks like "http://localhost:8080/myapp/verify.htm?verifyId=Agkvhs" My requests reaches my verify.jsp in ...

热门标签