阻止 flutter 生成双外键

发布于 2024-10-15 02:33:47 字数 2271 浏览 0 评论 0原文

当我从我的一个表中生成数据库作为每个字段的 2 个时,我不明白为什么

我有 fk 键,我希望它们看起来如何(StudentId),但它也生成了他们想要的键看起来(student_id)

   public class PermissionLevel
    {
        public virtual int PermissionLevelId { get; private set; }
        public virtual Student Student { get; set; }
        public virtual Course Course { get; set; }
        public virtual Permission Permission { get; set; }
    }

  public class PermissionMap : ClassMap<Permission>
    {
        public PermissionMap()
        {
            Table("Permissions");
            Id(x => x.PermissionId).Column("PermissionId");
            Map(x => x.Name).NvarcharWithMaxSize().Not.Nullable();
            HasMany(x => x.PermissionLevels);
        }
    }


public class PermissionLevelMap : ClassMap<PermissionLevel>
{
    public PermissionLevelMap()
    {
        Table("PermissionLevels");
        Id(x => x.PermissionLevelId).Column("PermissionLevelId");
        References(x => x.Permission).Not.Nullable().Column("PermissionId");
        References(x => x.Student).Not.Nullable().Column("StudentId");
        References(x => x.Course).Not.Nullable().Column("CourseId");

    }
}

  public class StudentMap : ClassMap<Student>
    {
        public StudentMap()
        {
            Table("Students");
            Id(x => x.StudentId).Column("StudentId");
            HasMany(x => x.PermissionLevels);
        }
    }

我的所有看起来都是这样,我得到


(来源:gyazo.com

ISessionFactory fluentConfiguration = Fluently.Configure()
                                                  .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("Connection")))
                                                  .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Framework.Data.Mapping.StudentMap>())
                                                  .ExposeConfiguration(BuidSchema)
                                                  .BuildSessionFactory();

When I generate my database from fluent one of my tables as 2 of every field and I can't figure out why

like I have the fk keys how I want them too look(StudentId) but it also generates the keys how they want it to look(student_id)

   public class PermissionLevel
    {
        public virtual int PermissionLevelId { get; private set; }
        public virtual Student Student { get; set; }
        public virtual Course Course { get; set; }
        public virtual Permission Permission { get; set; }
    }

  public class PermissionMap : ClassMap<Permission>
    {
        public PermissionMap()
        {
            Table("Permissions");
            Id(x => x.PermissionId).Column("PermissionId");
            Map(x => x.Name).NvarcharWithMaxSize().Not.Nullable();
            HasMany(x => x.PermissionLevels);
        }
    }


public class PermissionLevelMap : ClassMap<PermissionLevel>
{
    public PermissionLevelMap()
    {
        Table("PermissionLevels");
        Id(x => x.PermissionLevelId).Column("PermissionLevelId");
        References(x => x.Permission).Not.Nullable().Column("PermissionId");
        References(x => x.Student).Not.Nullable().Column("StudentId");
        References(x => x.Course).Not.Nullable().Column("CourseId");

    }
}

  public class StudentMap : ClassMap<Student>
    {
        public StudentMap()
        {
            Table("Students");
            Id(x => x.StudentId).Column("StudentId");
            HasMany(x => x.PermissionLevels);
        }
    }

all mine look like that and I get


(source: gyazo.com)

ISessionFactory fluentConfiguration = Fluently.Configure()
                                                  .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("Connection")))
                                                  .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Framework.Data.Mapping.StudentMap>())
                                                  .ExposeConfiguration(BuidSchema)
                                                  .BuildSessionFactory();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦断已成空 2024-10-22 02:33:47

我无法重复该问题,但请尝试以下操作:在您的配置中,更改映射以包含外键名称的约定,例如:

.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Framework.Data.Mapping.StudentMap>().Conventions.Add(ForeignKey.EndsWith("Id"))

有了该约定,您可以从各个映射文件中删除 Column() 调用并达到相同的结果。由于我无法重现您的确切问题,我希望这也能解决问题(我有一种预感,Fluent 的 AutoMap 功能正在以某种方式混合在一起,但看起来您的代码不允许这样做,所以这确实只是一种预感)。

I wasn't able to duplicate the issue, but try this: in your configuration, change the mappings to include a convention for the foreign key names like:

.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Framework.Data.Mapping.StudentMap>().Conventions.Add(ForeignKey.EndsWith("Id"))

With that in place, you can remove the Column() call from the individual mapping files and achieve the same result. Since I can't reproduce your exact issue, I'm hoping this will also clear up the problem (I have a hunch that Fluent's AutoMap feature is getting in the mix somehow but it doesn't look like your code is allowing for this, so it really is just a hunch).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文