CracLock
CracLock

Reputation: 663

Unable to use methods from Domain Service class in WCF Ria?

I am trying to build an silverlight application which takes user first name, last name, pass, email address in text boxes and then add these to the database.

For this i am using WCF Ria Services.

Steps i have followed are :

Added ADO.NET Entity Data Model and then Domain Service class in my project (in web part).

Now i have got some predefined methods in my DomainService Class like Insert, Update methods. I know how to show data in DataGrid but its not what i want.

What i want is to customize all this for :

When user clicks the submit button then there should be method inside this like AddInfo(all parameters) which can add all the data to my sql server database {at present LocalHost}.

In simple words accessing your database through custom methods to add data in sql server using WCF Ria Services

I know it was very simple while working in .net forms and all. But how about Silverlight & WCF ria ?

Please Suggest.

Upvotes: 0

Views: 2111

Answers (2)

ken2k
ken2k

Reputation: 49013

In simple words accessing your database through custom methods to add data in sql server using WCF Ria Services

What you should do is write a custom method in server-side.

On server-side, you have a DomainService class that should inherit from LinqToEntitiesDomainService<TContext>.

Simply add a method in this class with the Invoke attribute, for example:

[Invoke]
public void AddNewUser(string name, string firstName, int age)
{
    // Put logic here to add the user to the DB
}

The logic to add a user to the database is really simple, just create a new Entity, add it to the context and call context.SubmitChanges();

When you compile the client RIA Services project, the auto-generated proxy class that correspond to your DomainService will contain your new method, and you'll be able to call it using:

yourDomainContext ctx = new yourDomainContext();
ctx.AddNewUser("dsd", "ds", 42).Completed += (sender, e) =>
{
     // Called asynchronously when the job is done
};

Upvotes: 1

Leo
Leo

Reputation: 7449

If you already have the Insert method on your Domain Service, you should be able to call from the client:

//add your new data to the context
MyDomainServiceContext.Entity.Add(myEntity); //(where "Entity" is your entity Type)
//send all the changes to the server
MyDomainServiceContext.SubmitChanges();

Upvotes: 1

Related Questions