Search code examples
linqlinqpad

Use the data context as a method argument in LINQPad


I have a compiled assembly that contains a lot of my business logic rules which I would like to use inside of LINQ Pad. I can add a reference to the assembly using Query -> Query Properties, but once I have the reference how do I access the context?

My BL object expects an IMyDataSource object, not an individual IDbSet.

Normally in a LINQ Pad query, the individual DB sets are "magically" available via their names. For example

In normal .NET code I would write

Dim items As IQueryable(of Item) = DataSource.Items

but in LINQ Pad I would write it without a reference to the context.

Dim items = Items

Solution

  • Your LINQPad query is compiled into a sub-class of the Data Context, so your data source is available as Me. Therefor you can quality Items to Me.Items for the same result.