5

Is it possible to map one column twice using NHibernate?

<property name="CustomerID" index="IX_Customer" not-null="true" />
<many-to-one name="Customer" column="customerid" class="Customer" fetch="join" />

I need to have the raw ID in order to bind a WinForms control which only supports Binding using a value (instead of the Item itself).

 myControl.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", bs, "CustomerID", true));
falstaff
  • 3,413
  • 2
  • 25
  • 26

2 Answers2

7

Yes, just modify

<property name="CustomerID" index="IX_Customer" insert="false" update="false" not-null="true" />
hival
  • 675
  • 4
  • 5
  • Hm, is this working without getting an error like Jaguar mentioned? – falstaff Jan 26 '12 at 20:55
  • Didn't had any error since I used this solution, thanks! It's more a workaround for the moment, since I want to get rid of all those ID's.. – falstaff Feb 03 '12 at 13:11
0

You can but it's a really bad idea. see IndexOutOfRangeException Deep in the bowels of NHibernate

you should find some other way to bind the id from the entity to your control

Community
  • 1
  • 1
Jaguar
  • 5,929
  • 34
  • 48