locked
Update Model from the Database RRS feed

  • Question

  • Hi Experts,

     

    I am pulling my hair for the last two weeks trying to fix this problem.

     

    I've build a RIA application and was able to read, update, delete , and creat records.

     

    But I went back to the database (MS SQL Server) and added a new column to my table.

     

    Following that here are the sequence of events

     

    1.       Open the *.edmx file (e.g. Model1.edmx) from the Web project
    2.        Right-Click and select “Update Model from the Database”
    3.        Follow the wizard and updated the changes I’ve made to the database  (for example , adding a new column)
    4.     Build the solution
    5.    Delete my old Domain Service (e.g. "DomainService1.cs" and  "DomainService1.metadata.cs")
    6.   At this point I see the tables have been  updated successfully  (I could see the extra column I’ve added)
    7.  
    8.   Open oneof the .xmal page and was able to retrieve (read) records and display it on my DataGrid
    9.   However, I could NOT update, delete or add records back to the database.
    10. Please note  that before I have execute the “Update Model from the Database” (#2), I was able to update , delete and remove.

     

    Your help with this issue would be greatly appreaciated

    Wednesday, June 16, 2010 10:05 AM

Answers

  •  Do you have access to Sql Profiler to see what is being sent to the Database?

    What does your update method look like?

     
    public void UpdateCourse(Course currentCourse)
    {
       this.ObjectContext.Courses.AttachAsModified(currentCourse, this.ChangeSet.GetOriginal(currentCourse));
    }
     
    Wednesday, June 16, 2010 10:49 AM

All replies

  •  I'll assume Step 7 was regen your DomainService.

     

    What is stopping you from updating?  If you open your DomainService do you see the Update/Insert/Delete methods for your entities?  Did you maybe forget to check the 'Enable Editting' checkbox when you generated it?

    Wednesday, June 16, 2010 10:16 AM
  • However, I could NOT update, delete or add records back to the database.

     

    When you generate the DomainService1.cs the 2nd time, did you Select "Edit" CheckBox on each table? Or check if your service has Update/Insert/Delete function generated. If not, you can try re-generate your service again.

    By the way, you should not have to re-generate your service code if you only added one column to a Table. Service code should be the same. It does not have any column specific code. You might want to update your metadata class with this extra column, that's all you need.

     

     

    Wednesday, June 16, 2010 10:22 AM
  • Hi Dan,

    Thank you for your prompt response.

    Yes, I did check 'Enable Editing' and in fact I could see the Update/Insert/Delete methods in the DomainService.

    Somebody suggested a work around in the link below but did not work for me

    http://blog.davidyack.com/journal/2009/5/20/update-net-ria-services-domain-service-from-model.html

    Hab

    Wednesday, June 16, 2010 10:25 AM
  •  So if you can see those methods, what is stopping you from updating and inserting?

     

    Wednesday, June 16, 2010 10:30 AM
  • That is the exact issue I'm facing.

    Anytime you updated the model (e.g. Model1.edmx)  by selecting  “Update Model from the Database” the updating /deleting/inserting methods do not work.

    I was able to debug and could see the "UpdateTableName" is executed with no error but the updated value does not propage into the database

    Wednesday, June 16, 2010 10:40 AM
  •  Do you have access to Sql Profiler to see what is being sent to the Database?

    What does your update method look like?

     
    public void UpdateCourse(Course currentCourse)
    {
       this.ObjectContext.Courses.AttachAsModified(currentCourse, this.ChangeSet.GetOriginal(currentCourse));
    }
     
    Wednesday, June 16, 2010 10:49 AM