Insert record into db using linq2sql/datacontext

Question!

I am trying to insert a standard record into my db using linq2db, but i keep seeing examples to ADD method which i don't appear to have ... what i have currently is the following, as you can see i have my datacontext.... (no add method) ... the Reservation class is a separate class i created as a DTO - i presume this is correct?

Any help really appreciated,

    public bool AddReservation(Reservation reservation)
    {
        bool success = false;
        try
        {
            MiningDataContext db = new MiningDataContext();


            db.Reservations. // NO ADD HERE


        }
        catch { }

        return success;
    }


Answers
You should use the method InsertOnSubmit() and then call SubmitChanges().

public bool AddReservation(Reservation reservation)
{
    bool success = false;
    try
    {
        MiningDataContext db = new MiningDataContext();

        db.Reservations.InsertOnSubmit(reservation);
        db.SubmitChanges();

        ...

    }
    catch { }

    return success;
}
By : Ostemar


try

db.Reservations.InsertOnSubmit(reservation);
db.SubmitChanges();


Instead of doing db.Reservations.Add, just do Reservations.Add. Then use the db.SubmitChanges()

By : Web


This video can help you solving your question :)
By: admin