Hello. I have a database design issue that I am trying to also fit into Entity Framework. Its complex, I have inherited it and its too late to make drastic changes! I want to draw on others wisdom before I make a decision about how to go forwards...my original post was much longer, but I think the business logic details are probably not important.
So to state the problem simply, say I have two tables in the same database:
TableA
Id, (other columns...)
TableB
Id, TableId (<--- soft key), TableTypeId, (other columns...)
Now TableB has a "soft key" to table A, that normally could be a Foreign Key, but with the schema I have it isn't, and trust me it can't be (the reason is that "fake foreign key" points at any one of 76 different tables depending on what is in TableB's "TableTypeId" column).
Now, we are using Entity Framework. Clearly there cannot be a Navigation Property between the two tables. The problem is I need to work across these two tables in a single transaction. For example, when I add a record to TableA, I need to also add a record to TableB and use the new Identity value created in TableA for the TableB's "TableId" column.
With a Navigation Property, I can connect the two EntityObjects in memory and then call Context.SaveChanges() and EntityFramework does it all in a transaction. However without a Navigation Property I have to insert into TableA first, get the Identity and then insert into TableB using the results of the first insert. THis is two transactions...
I have heard that Entity Framework allows you do to more things with transactions in more complex situations, such as defining your own transaction scopes and using other parameters to COntext.SaveChanges(). Before I try this, however, I would like to know if my problem is solveable in a single transaction...
What options do I have here other than a schema redesign...
Thanks