![](/img/trans.png)
[英]How to ignore Foreign Key Constraints in Entity Framework Core SQLite database?
[英]Would the Entity Framework's navigational properties work if I drop foreign key constraints from the database?
如您所知,开发人员大多嘲笑表之间的关系,而不是使用表之间的物理关系(是的,如果在列上放置外键约束,则从一个表绘制到另一个表的线)。
但是我相信,如果导航属性不存在物理关系,则Entity Framework将无法正常工作。
那么,有什么办法吗?
我的课程:
public class Phones
{
public int ID { get; set; }
public string Model { get; set; }
public string Manufacturer { get; set; }
public List<Users> Users { get; set; }
}
public class Sims
{
public int ID { get; set; }
public string Code { get; set; }
}
这将从用户->模拟用户创建1-M关系。
但是,如果我删除外键约束并保持原样,导航属性将如何工作呢?
在这种情况下,最好从两个类中删除引用并在这些类之外手动处理关系:
public class Sims
{
public int ID { get; set; }
public string Code { get; set; }
//public User User { get; set; }
public int UserID { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.