I'm using Fluent NHibernate 1.3.0.717 (via the NuGet package) and have had 
pretty good luck until now.

My mappings worked fine for retrieving data -- I've got a full unit test 
suite for verifying that.
Now that I'm trying to stuff an entire object graph into the database, I'm 
having a problem with "GeneratedBy.Identity()"

The actual object graph is complex, but for the sake of simplification, 
assume Trip -> Day -> Activity, with a Trip having 0 to many Days, and a 
Day having 0 to many Activities.
Serializing Trip with Days works fine, but when I get to serializing the 
Activities in a Day, Fluent NHibernate (or maybe just NHibernate) is 
ignoring the existence of an identity PK.
I need to be able to work with these entities without updating the entire 
graph every time, so in general, there is no cascading.

Trip specifies "Cascade.None" for the Day relationship, and Day has 
"GeneratedBy.Identity()"
The generated SQL looks like this (parameters p0 thru p19 have been snipped 
for readability):
INSERT INTO obsv.s_day (obstrip_id /* <- Foreign key to Trip */) VALUES 
(@p20); select SCOPE_IDENTITY();@p20 = 145 [Type: Int32 (0)]
What is not present is the PK column for the table.

Now, when the activities for a day are to be saved, the generated SQL looks 
like this (again, bunch of parameters removed for readability):
INSERT INTO obsv.s_daylog (s_day_id, s_daylog_id /* <-- This is the 
identity PK for s_daylog and shouldn't be here */) VALUES (@p20, @p21); 
select SCOPE_IDENTITY(); @p20 = 1418 [Type: Int32 (0)], @p21 = NULL [Type: 
Int32 (0)]

This fails with the following error:

System.Data.SqlClient.SqlException : Cannot insert explicit value for 
identity column in table 's_daylog' when IDENTITY_INSERT is set to OFF.

I tried the advice from Joe Brockhaus to JamesF from late last month and it 
still doesn't fix the issue.  The current mapping for Day is as follows:

HasMany(x => x.Activities)
                .KeyColumn("s_day_id")
                .Cascade.None()
                .Not.LazyLoad()
                .Inverse();

Is this a bug, or am I missing something really simple?

P.S. If it really matters, I can point someone to the entire project on 
GitHub.  But for the purposes of getting an answer, I thought asking 
someone to wade through 6000 lines of
code wasn't going to win me any friends.

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/fluent-nhibernate/-/NfHN_dFrc7IJ.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to