Hi, I am new to fluent NHinbernate, now I face one problem with mapping composite keys. Can anyone pointing out the URL or sample please?
+4
A:
There's a UseCompositeId
method.
public class EntityMap : ClassMap<Entity>
{
public EntityMap()
{
UseCompositeId()
.WithKeyProperty(x => x.Something)
.WithReferenceProperty(x => x.SomethingElse);
}
}
James Gregory
2009-01-15 08:55:54
Note that in new versions of NHibernate UseCompositeId is replaced with CompositeId, and WithKeyProperty is just KeyProperty
Rob Walker
2010-10-28 17:20:01
+2
A:
Can find more detailed example here http://devlicio.us/blogs/derik_whittaker/archive/2009/01/16/using-fluentnhibernate-to-map-composite-keys-for-a-table.aspx
Derik Whittaker
2009-01-28 19:44:57
+1
A:
if this is your first class
public class EntityMap : ClassMap<Entity>
{
public EntityMap()
{
UseCompositeId()
.WithKeyProperty(x => x.Something)
.WithReferenceProperty(x => x.SomethingElse);
}
}
here is the second with a reference on Entity
public class SecondEntityMap : ClassMap<SecondEntity>
{
public SecondEntityMap()
{
Id(x => x.Id);
....
References<Entity>(x => x.EntityProperty)
.WithColumns("Something", "SomethingElse")
.LazyLoad()
.Cascade.None()
.NotFound.Ignore()
.FetchType.Join();
}
}
Lars Hildebrandt
2009-05-13 12:49:11