locked
A refereneced entity object instance of a data source created in a RIA service isn't calling the _inserting method of the object. RRS feed

  • Question

  • I wasn't sure how to word the title. I have a RIA service that references a data source in my "Spac.Server" project.

    In the RIA service I have this: 

    		public void UpdateEditableDepartmentFee(EditableDepartmentFee objEditableDepartmentFee)
    		{
    			. . .
    			
    				var MyLog = this.Context.CreateObject<Log>();
    				MyLog.Message = "Some Logging information.";
    				this.Context.Logs.AddObject(MyLog);
    				this.Context.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave);
    
    			. . . 
    		}

    In my "Spac.Server" project I have the following:

    		partial void Logs_Inserting(Log entity)
    		{
    			entity.User = this.Application.User.FullName;
    		}
     

    The Logs_Inserting method never gets called. Or at least it won't break there and the user value is not set.

    Don't the entity event methods get called? This works when I create a Log entry from the Spac.User project.

    Thanks.


    Scott Mitchell


    Monday, March 30, 2015 12:07 PM

Answers

  • The issue was that I was saving to multiple datasources without the proper configuration. Here's the article that cleared it up for me.

    https://msdn.microsoft.com/en-us/vstudio/hh313625?f=255&MSPPError=-2147217396


    Wednesday, April 1, 2015 5:22 PM

All replies

  • Can you set breakpoint to debug your application? or show me the error message you got?
    Tuesday, March 31, 2015 8:45 AM
  • Thanks Andrew. As far as I know I'm debugging correctly. I place a breakpoint on the Logs_Inserting event handler and the breakpoint is never hit.

    There is no error message. The app just doesn't allow me to set the field I created to store the name of the user that was making the change.

    I'm not being clear. The RIA service is a data source for a business object. In that RIA service I have a linked reference to a Lightswitch data source in order to create a Log object. I want to Log the changes made to the business object in the RIA service. I don't know how to get the User's name in the RIA service so I thought I could get it from the Application object in the entity's "Logs_Inserting" event handler that should be called in the Lightswitch code. But it doesn't call the "Logs_Inserting" and so never sets the user name.

    I hope that's a clearer way of describing the situation. It never breaks so there's nothing to show other than the code above. There's no error since the log entry does get inserted in the database just fine. It just doesn't have the user name set.



    Scott Mitchell

    Tuesday, March 31, 2015 1:19 PM
  • Hi!

    I guess you're right, it doesn't call methods on LS side.. Recently had similar request and I was left wondering why.. but, in my case, it wasn't a big deal to replicate LS methods in RIA service..

    cheers!

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Tuesday, March 31, 2015 1:23 PM
  • The issue was that I was saving to multiple datasources without the proper configuration. Here's the article that cleared it up for me.

    https://msdn.microsoft.com/en-us/vstudio/hh313625?f=255&MSPPError=-2147217396


    Wednesday, April 1, 2015 5:22 PM