开发者

nhibernate : Need to attach references before Update<T>(T entity)?

I'm, building an n-tier system using nHibernate i de back-end, and which is cummunicating using REST/json with the front-end.

When i send an object to the back-end, I only send the data like :

myAddress: [

{ guid: "1", street: "MyHomeStreet",

houseNumber: "34",

city: "6" }

]

So, I only send the referenced city entity's ID. When I deserialize this to my entity (server-side, upon arrival) , I lose this number, because server-side the reference is a real object, not an ID, and becomes null.

And then NHibernate does update the address but removes the reference in the db.

So do i really need to use relection for my entities to get al reference properties, and then, using the ID (6 in this example) , to retrieve the local city entity ( DAO.Get(6) ) and set all the references before doing a DAO.Update(myAddress) ???

This is really an overkill for realizing updates if i have to get all refe开发者_如何学运维rences (from cache or database) every time the server receives an update.

Or is there some ither way to do this?

Thanks!


You don't need to load the references from the DB.

If you have the ID, session.Load<TheEntity>(theId) returns a proxy for the requested entity and Id without going to the DB.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜