0
我有一個名爲Tarefa(任務葡萄牙語)模型:任何外鍵都必須自動需要?
public class Tarefa
{
[Key]
public int ID { get; set; }
[Required]
public string Assunto { get; set; }
public int ClienteID { get; set; }
public virtual Cliente Cliente { get; set; }
public int ProcessoID { get; set; }
public virtual Processo Processo { get; set; }
}
ClienteID和ProcessoID(非必需)
我並不需要選擇他們,當我創建一個新的Tarefa。
腳手架,增加遷移和更新數據庫中的表定義演出結束後:
CREATE TABLE [dbo].[Tarefas] (
[ID] INT IDENTITY (1, 1) NOT NULL,
[Assunto] NVARCHAR (MAX) NOT NULL,
[ClienteID] INT NOT NULL,
[ProcessoID] INT NOT NULL,
CONSTRAINT [PK_dbo.Tarefas] PRIMARY KEY CLUSTERED ([ID] ASC),
CONSTRAINT [FK_dbo.Tarefas_dbo.Clientes_ClienteID] FOREIGN KEY ([ClienteID]) REFERENCES [dbo].[Clientes] ([ID]) ON DELETE CASCADE,
CONSTRAINT [FK_dbo.Tarefas_dbo.Processoes_Pasta (se ajuizado)] FOREIGN KEY ([ProcessoID]) REFERENCES [dbo].[Processoes] ([ID]) ON DELETE CASCADE,
);
爲什麼這2列不是NULL?
因爲你使用'int'。如果你希望它們可以爲空,那麼使用一個可爲空的類型'int?' –