当我从我的一个表格中生成我的数据库时,每个字段中的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);
}
}
所有我看起来都是这样,我得到了
http://gyazo.com/b20cd95baa4cde6d8b06c98d50b8ddec.png
ISessionFactory fluentConfiguration = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("Connection")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Framework.Data.Mapping.StudentMap>())
.ExposeConfiguration(BuidSchema)
.BuildSessionFactory();
答案 0 :(得分:1)
我无法复制此问题,但请尝试以下操作:在您的配置中,更改映射以包含外键名称的约定,如:
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Framework.Data.Mapping.StudentMap>().Conventions.Add(ForeignKey.EndsWith("Id"))
有了这个,您可以从各个映射文件中删除Column()调用,并获得相同的结果。由于我无法重现您的确切问题,我希望这也能解决问题(我有一种预感,Fluent的AutoMap功能会以某种方式进入混合,但它看起来不像您的代码允许这样做,所以它真的只是一种预感。)