DBML - DataContext - How to insert?

  • Thread starter Thread starter Matthias S.
  • Start date Start date
M

Matthias S.

Hi there,

I have added a database model to my application and dragged a couple of
tables on it. Then I wrote a couple of selects using LINQ to SQL and
everything works fine.

But I can't fingure out how to add new items. For example, I have a
table named ServiceLog. I thought I could just go like:

MyDataContext db = new MyDataContext();
db.ServiceLog.Add(new ServiceLog() {...});

But there is no such Add method. Either I've got complete wrong
expectations about how entities for the model are generated, or I made
a mistake. Can anyone help? Thanks in advance.

Matthias
--
 
look for InsertOnSubmit; it is perhaps ironic that there used to be an
Add etc, but is was renamed because it was causing confusion (i.e.
peopele were confused when it didn't get added until SubmitChanges was
called).

Marc\
 
Hey Marc,

thanks a lot for your reply. Works perfectly. I was just looking in the
forest for trees :)

Kind Regards. Matthias
 
Matthias S. said:
MyDataContext db = new MyDataContext();
db.ServiceLog.Add(new ServiceLog() {...});

db.ServiceLog.InsertOnSubmit(...) and db.SubmitChanges();

- Michael Starberg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top