I have the following class
public class Room
{
public virtual Guid Id { get; set }
public virtual string Name { get; set }
public virtual Guid LocI开发者_Go百科d { get; set }
public virtual Location Loc { get; set; }
}
I start transaction and call Session.Save for a new entity and it writes it to the database correctly, but if I immediately call GetList() the list is returned with the Loc property assigned for all entities except for the new entity, but if I set the Loc before calling Save it is assigned for the new entity. Flush() does not solve the problem. What am I missing, I would prefer not to get the Location to set it.
Mapping both Loc
and LocId
is an incorrect usage of NHibernate.
Use room.Location = session.Load<Location>(locId)
to assign the Location.
You can use the Session.Evict
function to evict your object from the session, otherwise it will load your in session object for the given id. I would, however, highly recommend that you remove the LocId property from your mapping.
精彩评论