0

So I'm trying to do a simple insert using Linq but i'm running into trouble.

code:

        TestDatacontext db = new TestDatacontext ();
        Comment com = new Comment();
        com.UserID = userId;
        com.TaskID = taskId;
        com.Description = Server.HtmlEncode(txtComments.Text);
        com.DateCreated = DateTime.Now;   

Now at this point, from what I've read I should be able to do this:

db.Comments.Add(com);
db.Submitchanges();

However, when I write db.Comments. [There is no Add method]

So...how do I insert?

1 Answer 1

3

You're looking for db.Comments.InsertOnSubmit(com);

Sign up to request clarification or add additional context in comments.

2 Comments

Thansk man! Why did I keep seeing db.Comments.Add(com); I saw it on ScottGu's blog and others.
Well if you had a parent object Entity that had children Comments, then you would do myEntity.Comments.Add(com); db.Entities.InsertOnSubmit(myEntity);, I believe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.