apologies for the cross-post. Obviously, I'm using FluentNH to do my mappings, etc...
however I'm running into an issue with setting the value of a non-ID property with the next value of a sequence. Optimally, I'd like to specify in my mappings that this property is generated by a sequence. --- Is this possible? --- The origin of my question relies on the answer to that question, which no one has yet been able to divulge... - if yes, then how? (using NH, if it can be done in NH, i'll find a way to make it work in FNH) - if no, then the above is relevant... -- I'm using an IPreInsertEventListener to get ahold of the entity/ state prior to inserting. -- I'm querying the DB to get the nextval of the sequence I just need to know if there is a definitive way to map the entity property name to the index of that property in the state collection. (aka, if the index of the item in piEvent.Persister.PropertyNames ALWAYS maps to the index in piEvent.State?) Thanks for your time, ~Joe On Dec 8, 7:41 pm, fel0nious <[email protected]> wrote: > as i stated in my reply, the value is being retrieved via query. > more verbose detail: > > dbConn.Open(); > DbCommand dbc = dbConn.CreateCommand(); > dbc.CommandText = "SELECT [SeqName].NEXTVAL FROM dual"; > ticketNumber = dbc.ExecuteScalar().ToString(); > > the database is oracle 10g. > I'm not an oracle wizard by any stretch of the imagination, so I'm not > sure how i would go about having the value be generated on insert. I'd > imagine a trigger of some sort could be used. > Assuming that's true: If i have a trigger on the table to generate the > (non-ID) value from this sequence on insert (only), will NH pull that > value back into the entity? > > I'm confused by you having no idea how to map the property name to the > State collection (which is what's persisted to database). > It's obviously mapped somehow by NH, soo ... ? > (I suppose that's an NH, not FNH question, so perhaps my confusion > with your lack of insight is misplaced.) > > after playing around, i figure this MIGHT work, but I'm not confident > that these 2 collections are always synchronized. > > int propertyIndex = 0; > foreach (string prop in > piEvent.Persister.PropertyNames) > { > if (prop == "TicketNumber") > break; > else > propertyIndex ++; > } > piEvent.State[propertyIndex] = ticketNumber; > > all of this feels like a very kludgey hack: Is the limitation of not > being able to use sequence generators on non-ID-mapped fields a NH or > FNH shortcoming? > > On Dec 8, 7:17 pm, James Gregory <[email protected]> wrote: > > > > > > > > > I have no idea. > > > You say you want to set this property to the value of a DB sequence, > > where's this sequence coming from? How do you get the value? Can it not > > be a generated column in the db? -- You received this message because you are subscribed to the Google Groups "nhusers" 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/nhusers?hl=en.
