Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 28th, 2008, 02:05 PM
Kevin Buchan
Guest
 
Posts: n/a
Default Linq Selection Question.

Let's say I have a class, Employee, with three properties: EmployeeID,
Name, Active. I want to find all active employees, and I want to
return a sequence of an anonymous type containing all of the Employee
fields plus one more.

In SQL, I might do this like so:
SELECT E.*, CURRENT_TIMESTAMP AS [Today] FROM Employee AS E

I know I can do something like this in Linq:
'Assume that I have a collection, Employees, holding the data I want
to filter on.
Dim myEmps = From E in Employees Where E.Active = True Select
E.EmployeID, E.Name, E.Active, [Today] = DateTime.Now()

What I'd REALLY like to do is not have to type out all of the property
names (e.g. "E.EmployeID, E.Name, E.Active") just to get them all. I'd
rather do something like the SQL example of "E.*".

Is this possible with Linq?

(Please be patient of some of my code isn't exactly perfect... I typed
this directly into my newsreader.)

Thanks!!

--
Kevin Buchan
kevin.buchan@troutman[nospam]sanders.com
  #2  
Old August 29th, 2008, 01:15 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: Linq Selection Question.

Kevin Buchan wrote:
Quote:
Let's say I have a class, Employee, with three properties: EmployeeID,
Name, Active. I want to find all active employees, and I want to
return a sequence of an anonymous type containing all of the Employee
fields plus one more.
>
In SQL, I might do this like so:
SELECT E.*, CURRENT_TIMESTAMP AS [Today] FROM Employee AS E
>
I know I can do something like this in Linq:
'Assume that I have a collection, Employees, holding the data I want
to filter on.
Dim myEmps = From E in Employees Where E.Active = True Select
E.EmployeID, E.Name, E.Active, [Today] = DateTime.Now()
>
What I'd REALLY like to do is not have to type out all of the property
names (e.g. "E.EmployeID, E.Name, E.Active") just to get them all. I'd
rather do something like the SQL example of "E.*".
>
Is this possible with Linq?
What you can do is e.g.

Dim myEmps = From E in Employees _
Where E.Active = True _
Select E, [Today] = DateTime.Now()
but then the items returned has two properties, one of type Employees,
one of type DateTime so you would need to access

For Each item in myEmps
Console.WriteLine(item.E.EmployeeID)
Next

I don't think there is a wildcard like E.* possible.





--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles