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");
开发者_StackOverflow社区 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();
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).
精彩评论