Need Help in Mapping using Mapping by code

86 views
Skip to first unread message

Surya Pratap

unread,
Dec 14, 2011, 8:07:23 AM12/14/11
to Nhibernate
Hi,

I have a legacy database that I cannot change, the database diagram is

image.png


Can someone help me to map the tables using Nhibernate 3.2 mapping by code

I need help in mapping the  composite id columns between hsysObjPrp and hsysWebUserTablePref




image.png
hsysWebUserTablePrefMap.cs
hsysObjPrp.cs
hsysObjPrpMap.cs
hsysUser.cs
hsysUserMap.cs
hsysWebUserTablePref.cs

Fabio Maulo

unread,
Dec 15, 2011, 6:30:19 PM12/15/11
to nhu...@googlegroups.com
ComposedId(x=> x.Property(......))
ComposedId(x=> x.ManyToOne(......)) 
and so on

Surya Pratap

unread,
Dec 15, 2011, 11:59:11 PM12/15/11
to nhu...@googlegroups.com
I tried that, it returns an error saying

Foreign key (FK69321271EAA48866:hsysWebUserTablePref [Property])) must
have same number of columns as the referenced primary key (hsysObjPrp
[Object, SubObject, PrpName])

this is when I try to map

public class hsysObjPrp
{

public virtual string Object { get; set; }
public virtual string SubObject { get; set; }
public virtual string PrpName { get; set; }

public virtual System.Nullable<byte> PrpType { get; set; }
public virtual string PrpValue { get; set; }
public virtual System.Nullable<bool> Added { get; set; }
}

with

public class hsysWebUserTablePref
{
public virtual hsysUser User { get; protected set; }
public virtual hsysObjPrp Property { get; protected set; }

public virtual bool Hide { get; set; }
public virtual bool CanView { get; set; }
public virtual bool CanEdit { get; set; }

}

like so

public class hsysWebUserTablePrefMap : ClassMapping<hsysWebUserTablePref>
{
public hsysWebUserTablePrefMap()
{
Lazy(true);

ComposedId(x => x.ManyToOne(y => y.User));
ComposedId(x => x.ManyToOne(y => y.Property));

Property(x => x.Hide);
Property(x => x.CanView);
Property(x => x.CanEdit);
}
}


Reply all
Reply to author
Forward
0 new messages