I didn't understand exactly what you mean but this is an example extracted
from dome test I have committed yesterday (for the painful note, aka
composed id):
private class MyClass
{
private IMyCompo id;
public IMyCompo Id
{
get { return id; }
set { id = value; }
}
}
private interface IMyCompo
{
string Code { get; set; }
string Name { get; set; }
}
private class MyComponent : IMyCompo
{
public string Code { get; set; }
public string Name { get; set; }
}
var mapper = new ModelMapper(); mapper.Component<IMyCompo>(x => {
x.Property(y => y.Code, pm => pm.Length(10)); x.Property(y => y.Name); });
mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id)); var hbmMapping =
mapper.CompileMappingFor(new[] { typeof(MyClass) });
The mapping on the interface is used even if I don't want the interface
mapped as entity/component ;)
On Thu, Apr 28, 2011 at 12:01 PM, Michael DELVA <[email protected]>wrote:
> Hello all,
>
> I have this interface:
>
> public interface IBaseEntity : IEquatable<BaseEntity>
> {
> int Id { get; set; }
> bool IsTransient { get; }
> }
>
> public interface IStatistic : IBaseEntity
> {
> string Name { get; }
> bool Attack { get; }
> int Value { get; }
> }
>
> implemented by this abstract class:
>
> public abstract class Statistic : BaseEntity, IStatistic
> {
> public abstract string Name { get; }
> public abstract bool Attack { get; }
> public abstract int Value { get; }
> }
>
> This abstract class in derived in this class:
>
> public class MyStat : Statistic
> {
> public override string Name
> {
> get { return "Hello"; }
> }
>
> public override bool Attack
> {
> get { return false; }
> }
>
> public override int Value
> {
> get { return 100; }
> }
> }
>
> Using this mappings:
>
> mapper.Class<Statistic>(cm =>
> {
> cm.Id(a => a.Id, idm =>
> {
> idm.Access(Accessor.Property);
> idm.Generator(Generators.Native);
> });
>
> cm.Property(s => s.Name, pm => pm.Access(Accessor.ReadOnly));
> cm.Property(s => s.Attack, pm => pm.Access(Accessor.ReadOnly));
> cm.Property(s => s.Value, pm => pm.Access(Accessor.ReadOnly));
> });
>
> mapper.Class<Action>(cm =>
> {
> cm.Id(a => a.Id, idm =>
> {
> idm.Access(Accessor.Property);
> idm.Generator(Generators.Native);
> });
>
> cm.ManyToOne(a => a.Statistic, pm =>
> {
> pm.NotNullable(false);
> pm.Column("StatisticId");
> });
> });
>
> and this code:
>
> [Fact]
> public void Test()
> {
> using (ISession session = SessionFactory.OpenSession())
> {
> session.Save(new MyStat());
> session.Flush();
> }
> }
>
> I have this error:
>
>
> NHibernate.MappingException: No persister for:
> Emidee.CommonEntities.Tests.NHibernate.StatisticsInNHibernateTests+MyStat
>
> How should I change my mappings to make this work?
>
> Thanks in advance
>
> Michael
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
--
Fabio Maulo
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.