Toon Van Dooren
Toon Van Dooren

Reputation: 613

C# LINQ update statement

So i work according to the LINQ model and want to do an update using the where statement but i don't know how to pass my 2 ids down...

This is my code... The sc from my form:

tblEvk p= new tblEvk();
            p.fk_externvakID = currentCategoryId;
            p.fk_studentID = 2;

The bll:

 public void update(tblEvk p)
{
    DALstudent.update(p);
}

The DAL

 public void update(tblEvk s)
{
    var recordToUpdate = (from p in dc.tblEvks
                          where p.fk_studentID == id && p.fk_externvakID = vakid
                          select p).Single();

    recordToUpdate.evkBijlageGepost = 1;
    dc.SubmitChanges();
}

The question is how can i pass these variables? Using an insert i can just do public void insert (int id int vakid) but i cant do this with an update :(

Upvotes: 0

Views: 11697

Answers (2)

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79979

If the id and vakid are two properties of the entity tblEvks passed to the update method, then you can just do the following:

var recordToUpdate = (from p in dc.tblEvks
                          where p.fk_studentID == s.id && p.fk_externvakID = s.vakid
                          select p).Single();

Upvotes: 2

A.B.Cade
A.B.Cade

Reputation: 16915

I'm not I understand you right, but why not:

public void update(tblEvk s)
{
    var recordToUpdate = (from p in dc.tblEvks
                          where p.fk_studentID == s.fk_studentID && p.fk_externvakID = s.p.fk_externvakID
                          select p).Single();

    recordToUpdate.evkBijlageGepost = 1;
    dc.SubmitChanges();
}

Upvotes: 4

Related Questions