Alexander Kot
unread,Aug 18, 2011, 5:45:06 AM8/18/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nhu...@googlegroups.com
Hello all
I am playing with 3.2 mapping by code convention
I have
public class MyEntity : Entity
{
..................
public virtual IEnumerable<string> LinesBag { get; set; }
}
And next mapping:
m_mapper.BeforeMapBag += (insp, prop, map) =>
{
var tn = String.Concat(prop.GetContainerEntity(insp).Name, "_", prop.ToColumnName()).ToUpperInvariant();
map.Table(tn);
map.Key(km =>
{
km.Column(cm =>
{
var cn = String.Concat(prop.GetContainerEntity(insp).Name, "_ID").ToUpperInvariant();
cm.Name(cn);
cm.Index(String.Concat("IFK_", cn));
});
km.ForeignKey(String.Concat("FK_", tn, "_2_", prop.GetContainerEntity(insp).Name.ToUpperInvariant()));
}
);
};
m_mapper.Class<MyEntity>(map =>
{
//....................
map.Bag(x => x.LinesBag,
colmap => { },
xmap =>
{
xmap.Element(em =>
{
em.Column("Element");
});
}
);
});
As result NHibernate generate next script
create table MYENTITY_LINESBAG (MYENTITY_ID UNIQUEIDENTIFIER not null, Element NVARCHAR(255) null)
create index IFK_MYENTITY_ID on MYENTITY_LINES (MYENTITY_ID)
alter table MYENTITY_LINESBAG add constraint FK_MYENTITY_LINESBAG_2_MYENTITY foreign key (MYENTITY_ID) references MYENTITY
The questions:
1) Can i define column "Element" (It's name size and so on) not in explicit mapping but in convention rules BeforeMapBag and so on?
2) Can i define somehow covering index for this case
create index IFK_MYENTITY_ID on MYENTITY_LINES (MYENTITY_ID, Element)
?