none
Ordering of updates for a database modelled across multiple containers RRS feed

  • Question

  • We have a large database that we are refactoring into modules, with each module being one project, ie one DLL, with one .edmx, and one container.

    We understand that this prevents us from using navigation properties between classes in different modules; this isn't a problem for us.

    In the Web.Config, we therefore have an entry for each container, eg:

        <add name="ProductsContainer" connectionString="metadata=res://*/ProductsModel.csdl|res://*/ProductsModel.ssdl|res://*/ProductsModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;...&quot;" providerName="System.Data.EntityClient" />
      <add name="CustomersContainer" connectionString="metadata=res://*/CustomersModel.csdl|res://*/CustomersModel.ssdl|res://*/CustomersModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;...&quot;" providerName="System.Data.EntityClient" />
        <add name="RefDataContainer" connectionString="metadata=res://*/RefDataModel.csdl|res://*/RefDataModel.ssdl|res://*/RefDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;...&quot;" providerName="System.Data.EntityClient" />

    where the connection string is identical in all cases.

    Two questions, one easy and one less so:

    1. the easy qn: it seems that EF is intelligent enough to notice that the connection string is the same across all containers, and so uses just  a single database connection (and therefore transaction) when modifying objects in different containers.  Can you confirm this?

    2. the difficult qn: when a transaction modifies objects in more than one container, is there any way to know which container's SQL statements will be performed first.  eg, would updates to objects in ProductsContainer always be done before CustomersContainer?  We can of course test to watch what happens, but we want to know that whatever we observed is supported behaviour that won't change over time.

    Thanks

    Dan Haywood

    Monday, March 26, 2012 9:55 AM

Answers

All replies

  • Hi Dan,

    Welcome!

    For the first question: I think you must know Connection Pooling, I can confirm all the containers use the same connection string, the detail information is here: http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx

    For the second: For different context, you should use SaveChange(false) in your TransactionSope and call AcceptAllChanges() to submit the changes, I think you can control the order in this way: http://blogs.msdn.com/b/alexj/archive/2009/01/11/savechanges-false.aspx 

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 27, 2012 9:10 AM
    Moderator
  • Thanks for this, Alan.

    I realize now my questions are a little naive; ultimately the use of a TransactionScope (for my first question) and the order in which the contexts are interacted (my second question) with is under my control.  I asked because I'm actually using a framework [1] that does this for me, and hadn't looked in depth at its code.

    Thx again, your answer gave me the info to understand what the implementation of that framework code will do.

    [1] nakedobjects.codeplex.com

    Wednesday, March 28, 2012 6:49 AM
  • Hi Dan,

    You are welcome! I'm glad to help.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 28, 2012 6:51 AM
    Moderator