您好,使用流畅的 nibernate 自动映射
映射此
public virtual int Id { get; set; }
/*...snip..*/
public virtual MapMarkerIcon MapMarkerIcon { get; set; }
}
到此
CREATE TABLE [Attraction](
[Id] [int] IDENTITY(1,1) NOT NULL,
[MapMarkerIconId] [int] NULL
)
这样:
var cfg = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(connectionString)
.DefaultSchema("xxx"))
.Mappings(m =>
{
m.AutoMappings
.Add(
AutoMap.AssemblyOf<Partner>().Where(
n => n.Namespace == "xxx.Core.Domain")
);
m.FluentMappings.Conventions.Add(PrimaryKey.Name.Is(x => "Id"),
DefaultLazy.Always(),
ForeignKey.EndsWith("Id")
);
}
)
.ExposeConfiguration(c => c.SetProperty(Environment.ReleaseConnections, "on_close"))
.ExposeConfiguration(c => c.SetProperty(Environment.ProxyFactoryFactoryClass, typeof(ProxyFactoryFactory).AssemblyQualifiedName))
.BuildConfiguration();
为什么我会得到
Server Error in '/XXX.Web' Application. Invalid column name 'MapMarkerIcon_id'.
如何让 fluidnibernate 使用 MapMarkerIconId 而不是 MapMarkerIcon_id?
最佳答案
您需要一个 Id 约定。
参见http://wiki.fluentnhibernate.org/Available_conventions 和 http://wiki.fluentnhibernate.org/Convention_shortcut
关于fluent-nhibernate - 为什么 Fluent NHibernate AutoMappings 在 Id 上添加下划线(例如 Entity_id)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3395340/