fzxml
V2EX  ›  .NET

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

  •  
  •   fzxml · Feb 25, 2021 · 3714 views
    This topic created in 2098 days ago, the information mentioned may be changed or developed.

    最新在学习.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; }
    }
    
    4 replies  •  2021-02-27 16:34:00 +08:00
    cgpiao
    cgpiao
    Feb 25, 2021 via iPhone
    1
    去博客园吧,这里估计人少。
    beginor
    beginor
    Feb 25, 2021 via Android
    3
    最简单的办法就是先手工建表,不要用 EF 自动生成。 数据库表还是用数据库管理工具最好
    forgottencoast
    forgottencoast
    Feb 27, 2021
    4
    外键有什么不好吗?对于中小项目来说,没什么影响的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4679 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 06:31 · PVG 14:31 · LAX 22:31 · JFK 01:31
    ♥ Do have faith in what you're doing.