Search code examples
c#sql-serverwcfsilverlightwcf-ria-services

Who to create a custom method for data insert operation in silverlight?


I am using silverlight WCF Ria service to handle database related operations in my application.

I do have a table

Post(Id int identity,Title varchar(50), Content varchar(50), Date datetime, Comments varchar(50) );

I can easily use

public void InsertPost( Post post )

{
if ((post.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(post, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Posts.AddObject(post);
            }
}

I can use this to update database but for that i need to pass all the entries i.e Id, Content etc

I need one other method through which i can skip passing Id values. I want this method other than InsertPost method and how can i use that in my submitbutton_click event.

Please help


Solution

  • If you want to create a custom method for data insertion using RIA Services, this answer might help you.

    But remember that if Comments, Content, datetime...etc. are nullable in your database, then you could use the InsertPost without specifying them:

    Post newPost = new Post { Title = "title" };
    ctx.InsertPost(newPost);