aay
unread,Sep 29, 2009, 9:28:31 PM9/29/09Sign 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 nhusers
Hello,
I have an issue with a legacy DB I work with. I've got two tables
tbOrder and tbItem:
tbOrder (
OrderId varchar(10),
name nvarchar(100)
)
tbItem(
OrderId varchar(10),
detail decimal,
more int
)
The problem is, there are no foreign keys, and OrderId in tbOrder is
stored as an upper case string, while OrderId in tbItem is stored as a
lower case.
nHibernate mapping is as follows:
<class name="Order" table="tbOrder">
<id name="Id" column="OrderID" type="String">
<generator class="assigned"/>
</id>
<bag name="Items" table="tbItem" inverse="true" lazy="true">
<key column="OrderID" />
<one-to-many class="Item" />
</bag>
</class>
Classes are:
class Order {
public Id { get; set; }
public IList<Item> Items { get; }
}
class Item {
public decimal Detail {get;set;}
public int More {get;set;}
}
SQL queries are issued properly and nHibernate loads all entities (I
intercepted PostLoadEvent to check that instances of Item are
created), however created items are not added to the collection of
items in Order. My guess is that nHibernate does internal check on
"foreign" key and since strings are in different case nHibernate
discarts the items and does not add them into the collection. If I
manually update either of the keys (primary on tbOrder or 'foreign' on
tbItem) everything works fine. Unfortunately this solution is not
viable for the live application - there are millions of orders and
many more items.
I was trying to see if there is anything I can do and I tried the
following hacks:
1. In Order return lower case of Id in respective getter, but
nHibernate doesn't use Order.Id property and it seems to cache/get/use
DB value straight.
2. In Item: add OrderId property and do case conversion there as well.
No luck either.
Does anyone know of any way to overcome this issue? Any help or
direction would be greatly appreciated.
Thanks in advance