Les*_*zón 0 c# asp.net-mvc entity-framework
如何使表“ PRODUCT”的外键接受空值?
我要求在填写PRODUCT表单时,您可以保存信息而不必选择银行。我使用实体框架生成表单PRODUCT(Controller)
外键del模型产品-> “ public int EntidadID {get; set;}”
我有两个相关的模型。
public class Product
{
[Key]
public int ProductID { get; set; }
public string NumContrato { get; set; }
public float TasaReal { get; set; }
public decimal Capital { get; set; }
public DateTime FechaValor { get; set; }
public DateTime FechaVencimiento { get; set; }
public int Plazo { get; set; }
public int BankID { get; set; }
public virtual CATbank CATbank { get; set; }
}
public class CATbank
{
[Key]
public int BankID { get; set; }
public string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
小智 5
BankID是您的外键吗?
如果是这样,请在“产品”类中尝试更改
public int BankID { get; set; }
至
public int? BankID { get; set; }
并在数据库表中确保该字段可为空。
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |