Hi using fluent nibernate automappings
to map this
public virtual int Id { get; set; }
/*...snip..*/
public virtual MapMarkerIcon MapMarkerIcon { get; set; }
}
to this
CREATE TABLE [Attraction](
[Id] [int] IDENTITY(1,1) NOT NULL,
[MapMarkerIconId] [int] NULL
)
with this:
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();
Why do I get
Server Error in '/XXX.Web' Application. Invalid column name 'MapMarkerIcon_id'.
How can I make fluentnibernate use MapMarkerIconId instead of MapMarkerIcon_id?
None of the above links work. Here's the solution with links to current Fluent NHibernate & automapping documentation.
The issue (a simple example):
Say you have the simple example (from fluent's wiki) with an Entity and it's Value Objects in a List:
With tables which have e.g.
And a foreign key for shelfid -> Shelf.Id
You would get the error: invalid column name ... shelf_id
Solution:
Add a convention, it can be system wide, or more restricted.
Code example:
Now it will automap the
ShelfId
column to theShelf
property inProduct
.More info
Wiki for Automapping
See more about Fluent NHibernate automapping conventions
You need an Id convention.
See http://wiki.fluentnhibernate.org/Available_conventions and http://wiki.fluentnhibernate.org/Convention_shortcut