in

CodeSmith Community

Your Code. Your Way. Faster!

Help: Entity Update Problem ?

Last post 05-28-2007 7:04 PM by matt@kiwilamb.com. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-27-2007 11:57 PM

    Help: Entity Update Problem ?

    Hi

    I have the following code running AfterInsert of a DataSource control.
    What I'm trying to achieve is set the value MasterShow_Pk equal to a value.
    The code runs fine but  the Data Store is not being updated with the value.
     

     protected void _x_ShowsDataSource_AfterInserted(object sender, x.Web.Data.LinkedDataSourceEventArgs e)
    {
     x.Entities._x_Shows Show = (yBC.Entities._x_Shows)e.Entity;
     Show.MasterShow_Pk = 123;
     Show.EntityState = x.Entities.
    EntityState.Changed;
     Show.AcceptChanges();
     x.Data.
    DataRepository._x_ShowsProvider.Save(Show);
    }

    I used the line  Show.EntityState = x.Entities.EntityState.Changed; as when stepping through the code i found the EntityState = Unchanged; so was thinking that was the problem. But still there is no update happeing in the DataStore with the inclusion of this line.

    Help Needed

    Thanks
    Matt

     

     

    • Post Points: 35
  • 05-28-2007 10:44 AM In reply to

    • mwerner
    • Top 50 Contributor
    • Joined on 03-02-2006
    • Sweden
    • Posts 106
    • Points 2,376

    Re: Help: Entity Update Problem ?

    Hi Matt!

    Remove the lines

    Show.EntityState = x.Entities.EntityState.Changed;
    Show.AcceptChanges();    <=== This line resets the EntityState to Unchanged (this is done by the Save)

    and try again.

    Modifying the MasterShow_Pk should set the EntityState to Changed automatically and Save internally calls AcceptChanges after a successful save. If you call AcceptChanges before Save then Save will not know that the entity has changed.

    H.T.H


    Best regards,
    Magnus Werner
    • Post Points: 35
  • 05-28-2007 7:04 PM In reply to

    Re: Help: Entity Update Problem ?

    Thanks H.T.H for the response.

    I tried what you suggested and understand the logic, I'm using the following code now

     x.Entities._x_Shows Show = (x.Entities._x_Shows)e.Entity;
    Show.MasterShow_Pk = 123;
    x.Data.
    DataRepository._x_ShowsProvider.Save(Show);

    Still getting a timeout! So what I did was change the DataSource EnableTransaction="false"  and it works fine now.
    What is the issue here with Transaction managerment, something is not working right ?

    Thanks
    Matt

    • Post Points: 5
Page 1 of 1 (3 items)
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems