NH gives you a real schema-update ? I don't think so. btw you may ask a new feature to optionally execute the addition of AuxiliaryDatabaseObjects to SchemaUpdate (in this case the user will be responsible about the whole script; read it as IF NOT EXIST)
On Thu, Aug 5, 2010 at 5:04 PM, v64 <[email protected]> wrote: > Hi Fabio, > > I've tried this approach and it works for creating a new schema, but > not for upgrading an existing one. Being able to upgrade the schema is > an important requirement for our app, and this is one of the reasons > we chose NHibernate since it has support for it. > > Any other ideas? > > I'm looking at different ways to make this work but all of them > require code changes to core objects. Would you guys be OK if I > contributed a patch that would enable unenforced foreign keys? If so > what would be the best way to implement it? > > Thanks! > v > > > > On Aug 5, 11:49 am, Fabio Maulo <[email protected]> wrote: > > After add all mappings and before SchemaExport/BuildSessionFactory you > can > > iterate NH's metadata and auto-add database-objects. > > var mappings = > > > configuration.CreateMappings(Dialect.Dialect.GetDialect(configuration.Properties)); > > foreach (var table in mappings.IterateTables) > > { > > foreach(var fk in table.ForeignKeyIterator) > > { > > IAuxiliaryDatabaseObject auxdo = CreateAlterFk(fk ); > > mappings.AddAuxiliaryDatabaseObject() > > > > > > > > > > > > } > > } > > On Thu, Aug 5, 2010 at 12:33 PM, v64 <[email protected]> wrote: > > > Fabio, > > > > > Thanks for your quick reply. > > > > > I've tried to do this through a custom dialect and ran into a problem > > > because of the way NHibernate builds the constraint string. > > > > > ForeignKey.SqlCreateString() adds "alter table <table_name> ", then > > > calls > > > ForeignKey.SqlConstraintString() which appends the output from > > > Dialect.GetAddForeignKeyConstraintString(), normally something like > > > "add constraint [blah] foreign key ([blah]) references [blah]" > > > after that ForeignKey.SqlConstraintString() tacks on " on delete > > > cascade" if cascade delete is enabled. > > > > > What I need to generate is two separate commands for each foreign > > > key. > > > > > ALTER TABLE [pf].[Invoice] WITH NOCHECK ADD CONSTRAINT > > > [FKDC60817A07C258D] FOREIGN KEY ([BillTo]) REFERENCES [pf]. > > > [OrderContact] NOT FOR REPLICATION > > > ALTER TABLE [pf].[Invoice] NOCHECK CONSTRAINT [FKDC60817A07C258D] > > > > > I could output "WITH NOCHECK ADD CONSTRAINT ..." in > > > Dialect.GetAddForeignKeyConstraintString() and then tack on the second > > > ALTER to it (which is kind of a hack in itself). But now if cascade > > > delete is enabled, ForeignKey.SqlConstraintString() will add "on > > > delete cascade", and that will break it. > > > > > Any ideas? > > > > > TIA > > > v > > > > > On Aug 5, 9:44 am, Fabio Maulo <[email protected]> wrote: > > > > On Wed, Aug 4, 2010 at 6:48 PM, Jason Dentler < > [email protected] > > > >wrote: > > > > > > > You can probably create a custom dialect to do this. I'm not sure > if > > > > > there's an easier way. > > > > > > Yes Jason, that is the easy way. > > > > Method > > > > GetAddForeignKeyConstraintString > > > > -- > > > > Fabio Maulo > > > > > -- > > > 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]<nhusers%[email protected]> > <nhusers%[email protected]<nhusers%[email protected]> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/nhusers?hl=en. > > > > -- > > Fabio Maulo- Hide quoted text - > > > > - Show quoted text - > > -- > 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]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- Fabio Maulo -- 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.
