1

I am learning how to use Linqpad. Please see the code below (Linqpad C# Program):

//UPDATE (c# Porgram)
void Main()
{
    var v1 = Vendors.Single(x => x.BusinessEntityID == 1492);
    v1.Name = "Hello"; //Australia Bike Retailer
    SaveChanges();
}

It works as I would expect. I have two questions:

1) How does it work without the Linq To Entities Database context?
2) How would I delete v1?

Update

I have tried this following on from an answer below:

enter image description here

w0051977
  • 15,099
  • 32
  • 152
  • 329

1 Answers1

4

The code you write in LinqPad is actually inside your DB context.
Then you specified the connection, you were asked to point to the assembly that holds your DB Context.
That is how LinqPad knows.

To delete V1 do as you normally would:

Vendors.Delete(v1);
SaveChanges();

UPDATE
Dependending on which context you use, it could be:

Venders.Delete(v1);

or

Vendors.Remove(v1);
Community
  • 1
  • 1
Jens Kloster
  • 11,099
  • 5
  • 40
  • 54
  • I have made a change to my question. I get an error when I do this. – w0051977 Feb 01 '17 at 11:49
  • I am using a dbContext so have to use: Remove. Thanks for that. What is the method name for an insert? (for an upvote). – w0051977 Feb 01 '17 at 12:06
  • @w0051977 I would guess **.Add(v1)**. See this site for good tutorials: http://www.entityframeworktutorial.net/EntityFramework4.3/add-entity-using-dbcontext.aspx – Jens Kloster Feb 01 '17 at 12:16