How To

Scripts

A script is C# you write in the middle pane and run against a connection. DataPad compiles and executes only the script you typed; the object model it runs against is generated from the attached connection's schema.

Scripts

A script is C# you write in the middle pane and run against a connection. DataPad compiles and executes only the script you typed; the object model it runs against is generated from the attached connection’s schema.

Write and run

Type your script and press F5 (or click Run). The starter buffer already contains a working example. You may declare a void Main() or write top-level statements; both work. A connectionless script is supported, so Run is never gated on a connection.

The editor header’s connection dropdown attaches a connection to the script. With a connection attached, the script’s context object exposes the schema’s tables and columns under their C#-cased names. The host resolves the stored connection string when it runs the script; the string never crosses the editor.

Use Stop in the toolbar to cancel a run that is still in flight.

Dump results

Call Dump() to place a value in the output pane:

context.Albums.Take(100).Dump();
context.Albums.Count().Dump("Album count");

Each call appends a block in call order: scalars become value blocks, sequences of records become table blocks (with a labelled total above them), a single object becomes a property block. A large result is capped and the block says so instead of silently truncating. Read the blocks in the Results grid topic.

Using directives and packages

A script carries its own using directives and NuGet packages. Open the active script’s package manager from the Packages toolbar button or the badge in the editor header. There you can search the NuGet registry, add a package and its version, and see the packages the script has restored. The installer resolves the package list to its closure, cache-first.

IntelliSense and diagnostics

IntelliSense completion and the editor error popup are Pro capabilities. Without them the editor still compiles and runs your script, and compile failures are reported as a real diagnostic with its line number. Hover a squiggle to read the compiler’s message and its Roslyn code. The comment/uncomment chords are Ctrl+K Ctrl+C and Ctrl+K Ctrl+U by default.

Save and open

The Files menu holds New script, Open script…, Save script, and Save As…, each with its shortcut shown. Scripts are saved as .wf1dp files. Each open script is a tab; a tab with unsaved changes shows a dirty marker, and closing it asks before discarding. The active tab’s name and dirty state also appear in the window title.

Changed tabs are autosaved so a crash or an accidental close does not lose them. If that autosave fails, the app-close confirmation appears and names the real store error instead of closing silently.

Attach a connection and write data

A script attached to a write-enabled connection can change data through EF’s SaveChanges(). The output pane reports the Data writes block: the counts, the number of SaveChanges() calls, and the ordered statement list, with any statement expandable to its SQL and bound parameter values. A read-only connection blocks every write path; see the Connections topic.