.NET - Nieuwe connection providers in LINQPad
- Datum:
- Auteur: Stefan Cruysberghs
- Deze pagina is enkel in het Engels beschikbaar
A few weeks ago I started testing the beta version of LINQPad 1.35. Some days ago it has been officially released. This great tool from Joe Albahari was introduced in 2007 and nowadays it is a very mature tool which should be in the toolbox of every .NET developer. Version 1.35 offers new connection providers and it has native support for LINQ to SQL and the Entity Framework models. It also provides new query types like SQL and Entity-SQL.
I am a fan of this tool and I already demonstrated its features in many of my articles. I was probably one of the first developers who used LINQPad to execute LINQ to Entities queries. In the past you needed to add some references and create the ObjectContext in each script. It was a bit of work but it functioned fine. Now you can do the same thing with the new connection providers but they also offer many advantages. In this small article I will highlight some of the new features.
Connection providers
LINQPad 1.35 provides a renewed Add Connection wizard. There are 3 options to start with:
- Automatic: This was the only feature supported by the previous versions. It will automatically generate a LINQ to SQL DataContext and entities for the given SQL Server or SQL CE databases.
- Custom LINQ to SQL DataContext: This option can be used to specify an assembly which contains a LINQ to SQL context and its entities. You also have to specify the corresponding SQL Server database. This option is new and very interesting when you have tweaked a LINQ to SQL DataContext in Visual Studio.
- Custom Entity Framework ObjectContext: This option is also new and it makes it possible to query the ObjectContext of an Entity Data Model which you have created in Visual Studio. So all tweaks like renamed entities, properties or navigation properties, derived types, complex types, modified mappings, … will be available within LINQPad. Just browse and locate the assembly, choose an ObjectContext and Entity Data Model and specify the database.
Custom Entity Framework ObjectContext
Once you have added a new Custom Entity Framework ObjectContext connection, the schema explorer will show all collections (EntitySets) and the properties and navigation properties of each EntityType.
After creating a new Entity Framework connection you only have to select the connection in the Database combobox. Additional references and namespace imports are not needed anymore.
The new Entity Framework provider not only simplifies the queries, it also adds new features. When you execute a query the corresponding SQL statements will be logged. So you do not need ToTraceString() calls or the SQL Profiler anymore to see how the ADO.NET Entity Framework generates SQL statements.
SQL
LINQPad now also supports new query types. The SQL query type can be used to execute plain SQL Server statements. The SQL result pane also shows an Analyze SQL option. This can be used to add the SQL statement to a new query or to open it in SQL Management Studio.
There is another nice improvement when you have to execute long-running queries. In the new version the lambda expressions and the SQL translations will be displayed immediately after starting the query. Also the cancellation works better.
Stored procedures and views
The definitions of Views and Stored Procedures in an Automatic connection can now also be edited in LINQPad. The execute button will compile the view or the stored procedure.
ESQL
Another new query type is the ESQL query with which you execute Entity-SQL queries on Entity Framework ObjectContexts. Code completion and parameters are not supported (yet).
Autocompletion
Intellisense and autocompletion has been introduced in previous versions. This feature is not free but it only costs 19$. It works great and it really speeds up your developments. The autocompletion features in version 1.35 now also support smart tags for importing additional namespaces and autocompletion for indexers.
To put it briefly, download this tool, order an autocompletion license and querying LINQ to SQL DataContexts and Entity Framework ObjectContexts will become a lot of fun!