0

I have a few tables in SQL Server that I am using to log when a user logs into a Silverlight application.

I have created an entity for each of those tables. One example is ApplicationUsageLog, where I log the ApplicationID, the Date, and the UserID. Those are mostly pulled from the Silverlight side.

I would like to just create a method called Login(AppID,UserID) that can do an insert into that table.

Is that possible?

Thanks!

EDIT The following does not work for some reason:

    [Invoke]
    public void Login(int AppID,string EmployeeNo)
    {
        var aul = new ApplicationUsageLog{ ApplicationID = AppID, LoginDate = System.DateTime.Now, EmployeeNo = EmployeeNo };
        if ((aul.EntityState != System.Data.EntityState.Detached))
        {
            this.ObjectContext.ObjectStateManager.ChangeObjectState(aul, System.Data.EntityState.Added);
        }
        else
        {
            try
            {
                this.ObjectContext.ApplicationUsageLogs.AddObject(aul);
            }
            catch (System.Exception e) { }
        }
    }

I can look at aul and all looks good. But when I put a breakpoint at the end, this.ObjectContext.ApplicationUsageLogs is still totally empty....

nosirrahcd
  • 1,467
  • 3
  • 18
  • 36

2 Answers2

0

Yes, you can add a method to your Domain service class marked with the InvokeAttribute attribute. The method will appear as a method on the client context class.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
0

You can add your own custom methods to the DomainService if you want but it will not be called automatically when you insert into your context and SubmitChanges. You will have to call it manually.

If you want to override the implementation of your Insert method you can simply modify the contents of the Insert*EntityName* method in your DomainService.

Slugart
  • 4,535
  • 24
  • 32
  • I am hoping to do the whole "insert" thing server-side, never even instantiating the element on the silverlight-side (see edit). Is that possible? And thanks! – nosirrahcd Jun 18 '12 at 14:48
  • does it fail on ChangeObjectState or AddObject? – Slugart Jun 18 '12 at 15:40