I'm seeing this in two cases, I'll give one here. I have looked
through lots of NHibernate docs and messages and this seems like it
*should* be possible, so I'm wondering if there's something missing in
the Fluent-NHibernate mapping.

Here are the mappings (irrelevant parts redacted):


        public AdminMap() {
            HasMany( x => x.AdminAccesses )
                .AsBag()
                .KeyColumnNames.Add("admin_id")
                .Cascade.AllDeleteOrphan()
                .Not.LazyLoad();
        }


        public AdminAccessMap() {
            Id( x => x.Id, "admin_access_id" );
            References( x => x.Admin, "admin_id" );
            References(x => x.Group, "group_id");
            Map(typeof(AdminAccess).
                GetProperty("_function",
                    BindingFlags.NonPublic | BindingFlags.Instance),
                "function_id");

        }


My test case merely creates an instance, saves it, loads and deletes:


            Admin admin = new .Admin {Name = username, Password =
password};
            admin.AdminAccesses.Add(new AdminAccess
                { Admin = admin, Function = Function.AdminSettings,
Group = group});
            Admins.Insert(admin);

            Admins.Delete( admin );
            Assert.That(Admins.GetById(admin.Id), Is.Null);


NHibernate throws a SQL exception because it's trying to NULL the key
field:

System.Data.SqlClient.SqlException: Cannot insert the value NULL into
column 'admin_id', table 'AK_PROD_UN.dbo.t_admin_access'; column does
not allow nulls. UPDATE fails.
The statement has been terminated.


exec sp_executesql N'UPDATE t_admin_access SET admin_id = null WHERE
admin_id = @p0',N'@p0 int',@p0=31


I know that I *could* allow NULL on the admin_id foreign key but I
can't see why I would want to do that. The access list means
absolutely nothing (and therefore is basically orphaned) if it has no
admin_id.

Am I missing something? Shouldn't this work in a bidirectional
mapping?

--
Jeremy Wadsack
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to