2011-11-16 58 views

回答

1

我想你應該做的DB列的唯一一個。當插入重複項時,它會拋出異常。你可以捕捉並顯示給用戶一個錯誤。

+0

嗯,我使用EFCodefirst,如何在重寫OnModelCreating方法中定義英國? – Saeid

+0

在這裏你走,http://stackoverflow.com/questions/5701608/unique-key-with-ef-code-first – Illuminati

+0

我使用MVC 3和EF 4和代碼無法識別context.Database中的ExecuteSqlCommand。 ExecuteSqlCommand(「CREATE UNIQUE INDEX IX_Category_Title ON Categories(Title)」);這是關於版本還是其他? – Saeid

相關問題