开发者

Cannot add table in DBML designer with Foreign Key

I'm trying to add a small test table to the dbml designer, but it fails - nothing happends and there is no error message. The table is:

CREATE TABLE [dbo].[Car]
(
    CarID       INT NOT NULL IDENTITY(1,1)
    CONSTRAINT  PK_Car P开发者_如何学CRIMARY KEY CLUSTERED,
    RegNo       VARCHAR(7) NOT NULL,
    ModelID     INT NOT NULL
    CONSTRAINT FK_Car_Model FOREIGN KEY REFERENCES Model (ModelID)
)

If I drop the FK_Car_Model constraint it works. Am I missing something about how the designer works with relations?


A bit more than a year later, I came across the same situation again and this time it was solved by renaming a foreign key(!).

I have two tables Cars and Persons. Cars has a column OwnerID which is a reference to the owner. If the foreign key is named FK_Car_Owner it doesn't work. If the foreign key is renamed to FK_Cars_Owner it works.


I had the same problem until I restarted Visual Studio. Not ideal, but much better than removing all the foreign keys.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜