Distributed Environment - Replicated (staging) Database (deleting FK rows)http://forums.asp.net/t/1797384.aspx/1?Distributed+Environment+Replicated+staging+Database+deleting+FK+rows+Thu, 03 May 2012 04:36:49 -040017973844953271http://forums.asp.net/p/1797384/4953271.aspx/1?Distributed+Environment+Replicated+staging+Database+deleting+FK+rows+Distributed Environment - Replicated (staging) Database (deleting FK rows) <p>Hi all,</p> <p>Hoping someone could please answer this. What is the best practice for handling this situation?</p> <p>I am trying to create a system that will let me specify future changes on a set of entity objects (staging area). I was thinking the best way to do this would be to have&nbsp;a copy of the production database (just the schema), which I could then use my already developed application against in order to set properties on a given object and then create a&nbsp;method to&nbsp;push those changes back into the production database at a later time.</p> <p>I am trying to do this in an&nbsp;object oriented manner, I know that I can detach an object from one context and attach it to another, so I can push the objects back and forth between the two databases. The question is, how do I keep all of the FK contraints and referential integrity between the two databases intact?</p> <p>For instance:</p> <p><br> I have a set of tables that have columns that reference foreign keys from other tables.</p> <p>One such table:</p> <p>'DictionaryOrganSystem' with&nbsp;2 fields.</p> <p>1) row ID (primary key)</p> <p>2)Organ System Name</p> <p>&nbsp;</p> <p>I also have&nbsp;a table called 'OrganSystems' which is used as a 1-M table linking 'Tests' to organ systems and has 3 columns:</p> <p>1) row ID (primary key)</p> <p>2) TestInformationID (FK link to the TestInformation Table) &lt;--- this column is not relevant to the discussion.</p> <p>3) DictonaryOrganSystemID (FK link to the DictionaryOrganSystem table)</p> <p>&nbsp;</p> <p>What I would like to know is the best practice for avoiding exceptions in the entity framework and SQL when a row is deleted from the DictionaryOrganSystem table? I have the rule set to cascade, which means that the associated row in the OrganSystems table will be deleted automatically in the production database. But what about the tables/dictionaries in the &quot;secondary database&quot; that should somehow have a working knowledges of the changes that occured in the production system. I would think that this cascade should follow down to the secondary database as well from the production database.. can this be handled with triggers?&nbsp; Otherwise the method I develop to push the changes from the staging database to the production databse will cause an exception when adding a row that references&nbsp;the deleted DictionaryOrganSystem row.</p> <p>I am not sure the best practice of having a production database which has a &quot;staging&quot; area for future changes. Does anyone have a good article to reference?</p> <p>&nbsp;</p> <p>Thank you so much!</p> <p>Thanks,<br> Gene</p> <p>&nbsp;</p> 2012-04-26T15:46:26-04:004954683http://forums.asp.net/p/1797384/4954683.aspx/1?Re+Distributed+Environment+Replicated+staging+Database+deleting+FK+rows+Re: Distributed Environment - Replicated (staging) Database (deleting FK rows) <p>Take a look at database projects</p> <p>&nbsp;</p> <p><a href="http://msdn.microsoft.com/en-us/library/ff678491.aspx">http://msdn.microsoft.com/en-us/library/ff678491.aspx</a></p> 2012-04-27T10:41:12-04:004955656http://forums.asp.net/p/1797384/4955656.aspx/1?Re+Distributed+Environment+Replicated+staging+Database+deleting+FK+rows+Re: Distributed Environment - Replicated (staging) Database (deleting FK rows) <p>Hello&nbsp;ef305804&nbsp;</p> <p>If I understand you correctlyYou want a database and do many modifications to that data contents and then back them up automaticallySo as to make the two databases sychronizedAm I right</p> <p>If soI think you can do modifications to the certain databasesand then at a certain peroidplease set up something like back-up to back the whole database as a &quot;full copy&quot; after removing the older versionyou can always make your two database &quot;same&quot; and &quot;sychronized&quot;</p> <p>Reguards</p> 2012-04-28T01:14:10-04:004962913http://forums.asp.net/p/1797384/4962913.aspx/1?Re+Distributed+Environment+Replicated+staging+Database+deleting+FK+rows+Re: Distributed Environment - Replicated (staging) Database (deleting FK rows) <p>Hello ef305804</p> <p>First I was told that you couldn't replySo what's up now</p> <p></p> <blockquote><span class="icon-blockquote"></span> <p></p> <p>I am trying to find a way to define &quot;Future Changes&quot; to database objects. I was thinking that creating a second database with the same exact schema as the production data (minus all of the data) would serve as an area to hold the modified objects from the production database. These changed objects would then overwrite the objects in the production database at a future specified date.</p> <p>Sort of like a &quot;Staging Area&quot;, so that users can use my application to define a change right now, and have it actually happen at a future time. I was thinking this could be done by detaching the old entity object from the production context and re-attaching the new one that was defined in the staging database.</p> <p>Then I get into the issues of syncing the two databases FK objects as specified in the original post.</p> <p>Any help would be greatly appreciated!</p> <p></p> </blockquote> <p></p> <p>YesI think your ideatheorily speakingit's very nicehowever I think it's hard to do that</p> <p>You are &quot;future viewing&quot; the structureand if your db changes a lotI think the schema cannot be definedHow</p> <p>Until nowas far as I seeNo matter when you use the general ADO.NET, EF or LINQ-TO-SQLYour mapping real datatables should be always fixed one.</p> <p>Kindly correct me if I take you wrong</p> 2012-05-03T04:36:49-04:00