LINQ To SQL – Part 01
January 13, 2009 Leave a comment
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