Well I personally never allow direct access to my collections so I already have an AddPlayer method. It's a simple enough matter to go newPlayer.Game = this; and the two way relationship is intact.
On Oct 21, 7:06 pm, "Tim Barcz" <[EMAIL PROTECTED]> wrote: > Thanks for the input, that's exactly what I'm bumping into now. I presume > then you make it bidirectional to make your DBA happy? If that is the case > what steps are you taking in your code to ensure everything is working the > way you want? > > Tim > > On Tue, Oct 21, 2008 at 8:00 PM, Shane C <[EMAIL PROTECTED]> wrote: > > > Personally outside of an NHibernate environment I prefer uni because > > their is less complexity BUT within NHibernate I have yet to make uni > > relationships work WHEN there is a non-null constraint on the foreign > > key. The reason for this is that NHibernate ends up doing an insert, > > and then a separate update to set the relevant ID. For example the > > following table setup will NOT work for me: > > > Game Table > > GameId > > Name > > > Player Table > > PlayerId > > GameId (non-null foreign key to GameId) > > Name > > > NHibernate: INSERT INTO Game (GameId) VALUES (@p0); @p0 = '163840' > > NHibernate: INSERT INTO Player (Id) VALUES (@p0); @p0 = '196608' <- > > KABOOM! There is no GameId > > > Good luck finding a DBA that will agree to making GameId null-able > > because of that "silly" tool you're using. > > > On Oct 21, 2:36 pm, "Symon Rottem" <[EMAIL PROTECTED]> wrote: > > > I guess the primary issue is that if you do a bidirectional association > > you > > > need to keep in mind that the other end of the association (from the one > > > that's being modified) is not automatically updated so you need to add > > the > > > logic to manage this yourself. > > > > For example, take the ubiquitous example of an Order class with an > > > OrderLines collection which contains instances of the OrderLine class, > > which > > > in turn has has an Order property. > > > > What happens when you create a new OrderLine object? > > > > If you set the Order property of the OrderLine instance and you've mapped > > a > > > bidirectional association in your mapping where the collection end is > > mapped > > > as inverse so it's not in control of the association the data in the > > > database will be correct and when you load your Order or OrderLine both > > ends > > > of the association are correct. > > > > The problem, however is before you save and reload the changes using > > > NHibernate - the association in memory is not automatically handled so > > the > > > Order instance's OrderLines collection will not contain the new OrderLine > > > unless you explicitly add it yourself in your code. > > > > That's the primary reason I think most people avoid bidirectional > > > associations - if it's appropriate for you to use then use it, just be > > aware > > > of the extra work involved that NHibernate won't do for you. > > > > Cheers, > > > > Symon. > > > > On Tue, Oct 21, 2008 at 5:58 PM, Tim Barcz <[EMAIL PROTECTED]> wrote: > > > > I'm hearing and reading different things....is unidirectional or > > > > bidirectional the recommended way. > > > > > On certain scenarios I don't need to go unidirectional but then have a > > hard > > > > time mapping but then see people say unidirectional is bad. > > > > > Which is it? Uni or Bi? > > > > -- > > > Symon Rottemhttp://blog.symbiotic-development.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
