
最新在学习.net core, 在用 ef 自动建表的时候, 会自动在 avatar_id 字段上建立外键 FK_user_file_avatar_id, 有什么办法不建立外键但使用关联功能吗
public class User : Base { [Column(TypeName = "varchar(50)")] public string username { get; set; } [Column(TypeName = "char(69)")] public string password { get; set; } [Column("avatar_id")] public int AvatarId { get; set; } = 0; public virtual File Avatar { get; set; } } public class File : Base { [Column("name", TypeName = "varchar(128)")] public string Name { get; set; } [Column("hash_name", TypeName = "char(64)")] public string HashName { get; set; } } 1 cgpiao Feb 25, 2021 via iPhone 去博客园吧,这里估计人少。 |
2 Endward Feb 25, 2021 |
3 beginor Feb 25, 2021 via Android 最简单的办法就是先手工建表,不要用 EF 自动生成。 数据库表还是用数据库管理工具最好 |
4 forgottencoast Feb 27, 2021 外键有什么不好吗?对于中小项目来说,没什么影响的。 |