1 2 Previous Next 18 Replies Latest reply: Oct 4, 2012 9:57 AM by 931245 RSS

    Operation is not valid due to the current state of the object  EF 4 and 5

    931245
      I am trying to update some oracle tables that do not have PK's defined. I cannot modify the table structures. I can read data but when I try to update I get "Operation is not valid due to the current state of the object". [Edit:  I specified which columnns are primary keys in EF.  There are unique indexs on these columns].

      I am aware there is a bug in EF related to StoreGeneratedPattern. See http://stackoverflow.com/questions/8729279/updateexception-operation-is-not-valid-due-to-the-current-state-of-the-object-w

      I have carefully reviewed my .edmx and added the element in SSDL and CDSL. However I get this error with both EF4.1 and EF 5.

      Please see my post here for a sample of my .edmx file:http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/0e353c6b-8f69-4964-8c51-46d0fdb481af

      My update is just a simple retrieve/modify/save like this:

      MyModel Context = new MyModel(yada)
      Entity myEntity = Context.where...
      myEntity.Property = "X"
      Context.SaveChanges(); // Crashes here with Operation is not valid...

      Thanks for the help,

      Sam

      Edited by: 928242 on Sep 26, 2012 2:20 PM
        • 1. Re: Operation is not valid due to the current state of the object  EF 4 and 5
          Herald ten Dam
          Hi,

          there is "Bug 9721013 Windows: operation is not valid due to the current state of the object", it is found in ODP for .Net in versions below 12.
          So upgrade your ODP to at least version 11.2.0.2 or patch the current version. Patches can be found on Oracle Support.

          Herald ten Dam
          http://htendam.wordpress.com
          • 2. Re: Operation is not valid due to the current state of the object  EF 4 and 5
            931245
            Thank you Herald. Why do you say the bug exists in versions below 12 yet I should upgrade to 11.x?
            Also, I looked at Oracle.DataAccess.dll on my machine it says 4.112.3.0. How does that jive with 11.x versioning?

            Please confirm, thanks.

            Edited by: 928242 on Sep 27, 2012 8:49 AM
            • 4. Re: Operation is not valid due to the current state of the object  EF 4 and 5
              931245
              Thanks guys for yet another great public display of how good you really are.
              • 5. Re: Operation is not valid due to the current state of the object  EF 4 and 5
                Mark Williams-Oracle
                928242 wrote:
                Thanks guys for yet another great public display of how good you really are.
                It's possible that due to Oracle OpenWorld happening this week (and there was also the first beta release of the managed provider) that the folks who might be able to respond to this issue simply have not seen it or had the time to respond yet.

                Edited by: Mark Williams on Oct 3, 2012 11:14 AM
                • 6. Re: Operation is not valid due to the current state of the object  EF 4 and 5
                  931245
                  Thanks I'll let the project managers know and they will exend my deadline by a week or so.

                  By the way if the company I work for runs a little short on cash is it OK if we skip the license fee payment this month?
                  • 7. Re: Operation is not valid due to the current state of the object  EF 4 and 5
                    Mark Williams-Oracle
                    928242 wrote:
                    Thanks I'll let the project managers know and they will exend my deadline by a week or so.

                    By the way if the company I work for runs a little short on cash is it OK if we skip the license fee payment this month?
                    If it's a critical issue you should open a Service Request via My Oracle Support.
                    • 8. Re: Operation is not valid due to the current state of the object  EF 4 and 5
                      931245
                      So you're saying I should pay more money to fix software I've already paid for because the support service that is included with my purchase isn't being provided?

                      Did I get that right?
                      • 9. Re: Operation is not valid due to the current state of the object  EF 4 and 5
                        Mark Williams-Oracle
                        928242 wrote:
                        So you're saying I should pay more money to fix software I've already paid for because the support service that is included with my purchase isn't being provided?

                        Did I get that right?
                        No.

                        I'm saying if it is a critical and/or time sensitive issue, My Oracle Support would be a more appropriate option rather than using a free community/volunteer forum.

                        While I can't speak for everyone on the forums (of course), or Oracle for that matter, I suspect most people that respond here do so if/when they have time and the knowledge related to the question at hand.

                        If no one has yet responded satisfactorily to your particular issue it is likely a result of the above in my view.

                        What "support service that is included with [your] purchase isn't being provided" do you mean? If you have a support contract you can create a Service Request for ODAC issues.
                        • 10. Re: Operation is not valid due to the current state of the object  EF 4 and 5
                          931245
                          I stand corrected. I guess it was silly of me to post a question related ODP.NET in an ODP.NET forum. And I should realize that four business days is not nearly enough time to answer at thirty second question. And its silly of me to think an Oracle employee who wrote a book on ODP could answer my simple question in far less time than it takes to bicker mindlessly with me about about support options. What was I thinking!
                          • 11. Re: Operation is not valid due to the current state of the object  EF 4 and 5
                            Mark Williams-Oracle
                            928242 wrote:
                            I stand corrected. I guess it was silly of me to post a question related ODP.NET in an ODP.NET forum. And I should realize that four business days is not nearly enough time to answer at thirty second question. And its silly of me to think an Oracle employee who wrote a book on ODP could answer my simple question in far less time than it takes to bicker mindlessly with me about about support options. What was I thinking!
                            OK, a couple of points to perhaps reset the stage here (or whatever cliché you care to use...)

                            - I want anyone using Oracle products to be successful with those products.

                            - If I am able to help someone I try to do so when possible.

                            - I have never done anything at all with Entity Framework (or nHibernate) so I am not qualified to address the specific issue you are experiencing.

                            - I raised the option of submitting a service request to support because they very well could respond to this issue as it has not (clearly) been done so via the forums.

                            - It may not in actuality be a thirty second answer to the question.

                            - It is sometimes much easier to provide a test case (if needed) to support than over the forums interface.

                            - Support may be able to more quickly confirm if a known issue (such as the one posted by another user earlier) is applicable to a particular case or not.

                            - Your point(s) about paying for support in relation to products you already have and the forums is confusing to me. This is a public/free/community forum and not part of support per se.

                            - My response is not meant as bickering; rather, it was intended to clear my confusion as to whether you had support as it would apply to ODP and you could create a Service Request.

                            So, having said the above, I had already earlier reached out to an internal resource in regard to this particular forum thread. I do not know what sort of response I will receive.

                            Again my main point was (however poorly supported) that the forums are a community resource - some of the people who participate are Oracle employees but a great deal are not.

                            There's no guarantee of any response to a particular issue/thread. I think that would be the case on any community forum. So, despite your feelings that 4 business days is enough time, it's highly possible that no satisfactory response was provided because no one capable of doing so has either (a) seen the thread or (b) had the proper time to respond. But that is conjecture on my part I admit.
                            • 12. Re: Operation is not valid due to the current state of the object  EF 4 and 5
                              931245
                              OK enough said. Thanks for your time Mark.
                              • 13. Re: Operation is not valid due to the current state of the object  EF 4 and 5
                                Mark Williams-Oracle
                                I did get a reply from the internal resource I mentioned and hopefully he will be able to at least look at this thread "soon".

                                It's often difficult to convey tone or inflection in black and white text but I am sincere when I say I do want to help people be successful with our products.

                                Anyway, let's see if "the other person" will have a meaningful answer (or more questions)...
                                • 14. Re: Operation is not valid due to the current state of the object  EF 4 and 5
                                  15208
                                  Since your table does not have primary key defined and has only not null column(s), you will get the following waning in the edmx file. Basically, the table is read-only. Getting an error upon update is expected.

                                  <!--Errors Found During Generation:
                                  warning 6002: The table/view '<schema_name.<table_name>' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view.
                                  -->

                                  This limitation is not ODP specific.
                                  Furthermore, you most likely will get an error at UPDATE with other provider as well. Only the error message is different.

                                  Having said that, I suggest that use a custom stored procedure to workaround the limitation.
                                  The stored procedure should update the table with proper parameter types and values. For example,

                                  create or replace procedure updatemytable(param1 number, param2 number, ...)
                                  is
                                  begin
                                  update mytable set col_2 = paramX where col_1= param1 and col_3 = ...;
                                  end;


                                  Notes:
                                  1. You must include the custom stored procedure into your model in an EDM wizard step. Certainly, you may use "Update Model from Database...".
                                  2. Double-click on the edmx file, right-click on the table, and select "Stored Procedure Mapping" from pop-up menu.
                                  3. In the "Mapping Details" window at the lower part, select the stored procedure under <SelectUpdateFunction> and make sure the
                                  mapping between parameters and columns is correct under "Property" column.

                                  By doing so, EF will not create an UPDATE statement behind the scene for you. Instead, it will call your custom stored procedure to update your desired table.
                                  1 2 Previous Next