a little help with NHibernate mapping over legacy database?
I am re-writing an app that sits over a legacy database. I'm using NHibernate and I've had problems getting some mappings to work and would like some help.
First, the table structure:
Tech:
Id
FirstName
LastName
User:
TechID
Username
The "User" table开发者_StackOverflow社区 has no primary key. Foreign keys are no enforced at all. TechId is support to correspond to the Id on the Tech table.
My classes in memory are:
Tech:
Id
FirstName
LastName
User (type: User)
User:
Id
Username
The tables and objects will always be 1-1.
At first I tried a HasOne relationship in the mappings but everytime it tried to save it did an update instead of an insert and when creating a new record I would get the infamous "update count expect: 1, actual:0 " type message.
I am also fine with changing my model so the Username is directly on the Tech but I can't get that mapping to work either.
Any suggestions are greatly appreciated.
Thanks
Well don't I feel silly. Some searching of the docs and I found the JOIN config. I collapsed the Username property onto the Tech and done.
精彩评论