Creating DynamicDataContextDriver for linqpad c #

I am trying to create a driver for linqpad and ask a question:

When I create a DynamicDataContextDriver , I have to create a TypedDataContext class.

  • What should I put in it?
  • How will it be populated?
  • Can I control how it will be filled?
  • If I use a database of objects here, is there something I should keep in mind?

I found the answer here , but I can not find there all of the above answers.

+6
source share
1 answer

A typed data context is simply a class with properties / fields suitable for queries. These properties / fields usually return IEnumerables or IQueryables. For instance:

 public class TypedDataContext { public IEnumerable<Customer> Customers { get { ... } } public IEnumerable<Order> Orders { get { ... } } ... } 

When you use Visual Studio to create a new element of the form "LINQ to SQL classes" or "ADO.NET Entity Data Model", Visual Studio creates a typed data context for you, which is a great example of what LINQPad expects. The context of typed data can also expose methods (for example, to display stored procedures or functions) - in fact, it can reveal everything that makes sense to the end user.

When executing a query in a LINQPad that has a connection, LINQPad subclasses the typed data context associated with the connection so that the query has access to all its fields / properties. This is why Customers.Dump() is a valid request - we can simply access Customers without first creating an instance of typed data.

The LINQPad driver can work in one of two ways. Either it can act like Visual Studio and create a typed data context automatically and on the fly (dynamic data data driver), or it can extract a typed data context from an existing assembly provided by the user (static data context driver). When you add a connection to LINQPad, you will notice that the drivers are listed in two lists ( automatically configure the data context = dynamic driver and use the typed data context from your own assembly = static driver).

A typed data context is created each time the query is executed. Since its properties usually return lazily evaluated IEnumerables / IQueryables, it is not useful to think about โ€œpopulatingโ€ it. However, he will need to learn how to access the underlying data source, and this is done by passing arguments to the constructor .

LINQPad usually supports waiting for a request domain between requests, and this can be useful when caching and optimizing if you are writing a driver for a database of objects. Other than this, there should be no special considerations for object databases.

+3
source

All Articles