views:

27

answers:

1

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?

+3  A: 

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

JustLoren
Thansk man! Why did I keep seeing db.Comments.Add(com); I saw it on ScottGu's blog and others.
Jack Marchetti
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.
JustLoren