I’ve just begun using LINQPad and so far I like it but most tutorials I have come across for LINQ TO SQL make use of a DataContext class which is generated by Visual Studio for persisting updates etc. I am also fairly new to LINQ TO SQL so my question is what is the equivalent of the following in LINQPad (if there is one)…
MyDbDataContext db = new MyDbDataContext();
...
db.SubmitChanges();
Short answer: You do not need to create the DataContext yourself. LINQPad comes with lots of samples, take a look at them.
When you connect LINQPad to a database, it creates the DataContext for you. The DataContext’s tables (
Table<T>) andSubmitChanges()are available as local members.For example, LINQPad’s default “C# Expression” mode you can just write:
In LINQPad’s “C# Statement” mode:
LINQPad’s
Dump()extension method is very useful can be called on any object or collection (in LINQPad’s statement mode) to show the results below.Note that you don’t even need to connect to a database to use LINQPad. You can work with in-memory collections:
In fact, you don’t even need to use LINQ to use LINQPad. It also works great as a snippet compiler.