This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, we are developing an application using 2 databases. First one (master) is used only for creating/updating/deleting data and the second one is replicated real-time (may be few seconds delay) and used only for reading data. There is a balancer which routes SQL queries that routes them according to their context to first or second DB. In our mapped model we use IdentityColumn as an IdentityMethod. I have a question. Is there a way to "turn off" auto-update of ID column and update the ID column manually within UnityOfWork? Thanks, Igor. |
|
|
You can do this by overriding the Entity.GeneratedId() method. Note that this is called by the framework when it needs to know the ID you want assigned (typically when you call IUnitOfWork.Add): there is no API you can call directly to assign the ID yourself. Also note that because LightSpeed gives special handling to IdentityMethod.IdentityColumn, GeneratedId() does not play nicely with IdentityColumn. So you will want to set the IdentityMethod to something else (it doesn't matter what) in contexts where you will be implementing the override. Given your application I guess you will want to be able to use IdentityColumn in one context and GeneratedId() in the other, but the same entity class definitions. This requires a bit more ingenuity because GeneratedId() completely supplants the IdentityMethod. So your GeneratedId() implementation will probably want to check the context and delegate to the base implementation in the auto-update context, e.g. protected override object GeneratedId() { where you will need to implement IsAutoUpdateContext and GetDesiredId() to reflect how you want to tell LightSpeed which context it's in and how you are going to notify each entity of its desired ID. |
|
|
Thank you Ivan, I think I'll be able to do it like you suggested on per Entity basis, since I don't need to override ID generation on each Entity. |
|