Hi,
I'm using nhibernate via activerecord. I have a simple master and a detail table, Member and MemberDetail... In the MemberDetail table I have a CityId column which is not nullable and is not a foreignKey for City table. If a member does not want to indicate his/her city this field contains "-1" value. When i call my Member's ActiveRecord entity class like Member.FindAll(), i got an exception "Cannot insert the value NULL into column 'CityId', table 'MemberDetail'; column does not allow nulls". I traced the sql queries via Sql Server Profiler and I saw that nhibernate executes two sql update queries for each row it has just selected (one for Member and one for MemberDetail). Then I changed the CityId column to nullable. After this alter Member.FindAll call executed without any exceptions but in the database CityId columns, which have "-1" value, returned NULL because of nhibernate's update queries.
My first question, why are these update queries are executed, are they really necessary? And second, is there any way to prevent from these update queries. I think i have to do something with dynamic update or optimistic locking. I tried some combinations of these attributes but had no success.
Hope my issue is clear, Thanks in advance.
|