我有以下型號:實體框架 - 與外鍵刪除對象,並保留父
public class Company
{
//Primary key
public string ID { get; set; }
//Foreign key
public int? LogotypeID { get; set; }
}
和
public class Logotype
{
//Primary key
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int? ID { get; set; }
//Foreign key
public string CompanyID { get; set; }
}
如何從公司表中刪除標識,沒有刪除公司行?
使用:
http://msdn.microsoft.com/en-us/library/system.data.entity.dbset.remove(v=vs.113).aspx DbSet.Remove(打印商標)thows以下異常:
{"The DELETE statement conflicted with the REFERENCE constraint \"FK_dbo.Companies_dbo.Logotypes_LogotypeID\". The conflict occurred in database \"ShipReg\", table \"dbo.Companies\", column 'LogotypeID'.\r\nThe statement has been terminated."}
任何想法?
BR, 添
是公司ID是外鍵? –
您使用的是數據遷移嗎?如果是,您是否將級聯刪除設置爲true? – Marc
@Rudresh。是的,CompanyId是外鍵。 –