Forcing an identity insert with NHibernate / Fluent Nhibernate
We have a fairly robust system using NHibernate, we're in the middle of migrating from a single databas开发者_JAVA技巧e server to having two servers, one for administration and one for our public facing web site. This is mainly so that we can do things like content management with workflow that won’t affect the current site. As of today, they are two databases in the same server, but over time I can see using two physical machines with a web service call to push data.
So as an example, one of our marketing guys decides to introduce a new promotion through the admin , and schedule it for 2 weeks from now. We are working on a scheduling system that would push the new promotion to our production server when it’s kicked off. The intent was to use the same NHibernate providers for the data pushes, but we need to maintain referential integrity.
We’re using fluent nhibernate, and I can see writing two different class maps, and then using a some form of dependency injection ( IE structure map) of choosing which map to load. I was hoping for a better answer as that seems impossible to maintain as the system grows. Any suggestions?
ISession.Replicate is not supported with DB generated ID values. As illustrated by this issue in the NHibernate issue tracker.
- I suggest either to use your own ID generator or Guid/Guid.Comb since you'll be able to use NHibernate's replication in that case (as explained in the issue)
- You can also write your own replication code which does not use NHibernate, if it's simple enough this is doable.
- Use replication technology that your DB supports. I've used replication between MS SQL Servers before, and it's not that hard to set up. I'm quite sure other RDBMS's support similar stuff.
精彩评论