相关疑难解决方法(0)

实体框架 - 删除带有外键的对象,保留父对象

我有以下型号:

public class Company
{
    //Primary key
    public string ID { get; set; } 

    //Foreign key
    public int? LogotypeID { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

public class Logotype
{
    //Primary key
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int? ID { get; set; }

    //Foreign key
    public string CompanyID { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

如何从公司表中删除标识而不删除公司行?

使用:
http://msdn.microsoft.com/en-us/library/system.data.entity.dbset.remove (v=vs.113).aspx DbSet.Remove(Logotype) 会引发以下异常:

{"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."} …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework ef-code-first

1
推荐指数
1
解决办法
9335
查看次数

标签 统计

c# ×1

ef-code-first ×1

entity-framework ×1