LINQ To SQL – Part 01

I started playing around with LINQ to SQL This AM.  I tried to enumerate all of the running processes on my machine using the following LINQ:
 

var

query =

from p in System.Diagnostics.Process

.GetProcesses()

select new

{p.SessionId.ToString(), p.ProcessName};

ObjectDumper.Write(query);

  

and I got the following error:
Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
An anonymous type must be declared with a member assignment, simple name, or member access.

Apparently, you need to have real variable names for each property you create (note the bold):

 

select

 new {sessionId = p.SessionId.ToString(), p.ProcessName};

Did the trick

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: