Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query sys tables using LINQ-to-SQL?

I am using LINQPad and I want to get the list of instance pipe names from the sys.dm_os_child_instances table. How is that expressed in LINQ-to-SQL?

This doesn't work:

from n in sys.dm_os_child_instances
select n

I don't think it matters, but I am using SQL Server Express 2008.

Also, yes, I know I can run raw SQL from LINQPad.

like image 594
jedatu Avatar asked Jan 31 '11 05:01

jedatu


People also ask

How LINQ queries converted into SQL queries?

LINQ to SQL translates the queries you write into equivalent SQL queries and sends them to the server for processing. More specifically, your application uses the LINQ to SQL API to request query execution. The LINQ to SQL provider then transforms the query into SQL text and delegates execution to the ADO provider.

What are SQL sys tables?

sys. tables is a system table and is used for maintaining information on tables in a database. For every table added to the database, a record is created in the sys. tables table.


1 Answers

LINQPad allows this query if you tick the 'Include System Views and SPs' checkbox in connection properties.

A couple of other points:

  • If you have capitalization enabled, it's sys.Dm_os_child_instances rather than sys.dm_os_child_instances

  • The query "from n in sys.Dm_os_child_instances select n" is valid but frivilous: you can just go "sys.Dm_os_child_instances"

like image 144
Joe Albahari Avatar answered Sep 24 '22 02:09

Joe Albahari