有用.net core 的大佬吗,问个 EF 的问题

2021-02-25 12:02:35 +08:00
 fzxml

最新在学习.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; }
}
2109 次点击
所在节点    .NET
4 条回复
cgpiao
2021-02-25 12:06:33 +08:00
去博客园吧,这里估计人少。
Endward
2021-02-25 12:14:23 +08:00
beginor
2021-02-25 22:14:16 +08:00
最简单的办法就是先手工建表,不要用 EF 自动生成。 数据库表还是用数据库管理工具最好
forgottencoast
2021-02-27 16:34:00 +08:00
外键有什么不好吗?对于中小项目来说,没什么影响的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/756139

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX