Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 29th, 2010, 08:09 PM
Authorized User
Points: 160, Level: 3
Points: 160, Level: 3 Points: 160, Level: 3 Points: 160, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2004
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default LINQ Anonymous Type - Alias

Hi

When creating an anonymous type with the following code

.....

var allShips = from ship in myDataContext.CruiseShips
select new { ship.Name, ship.CruiseLine.Name};

........

I get the following error 'An anonymous type cannot have multiple properties with the same name.' I could avoid this my renaming the fields (LineName & ShipName) but am loathe to mess about with my naming conventions for the sake of making it work. Is it possible to use aliases, or is there a simpler solution?

regards, Guy
  #2 (permalink)  
Old August 30th, 2010, 02:53 AM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default RE: LINQ

Try this;

var allShips = from ship in myDataContext.CruiseShips
select new { ShipName=ship.Name, CruiseName=ship.CruiseLine.Name};


Rajeev.
  #3 (permalink)  
Old August 30th, 2010, 06:21 AM
Authorized User
Points: 160, Level: 3
Points: 160, Level: 3 Points: 160, Level: 3 Points: 160, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2004
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Rajeev,

It works. Can you recommend a site/resource which covers Linq (for beginners!) matters like this?

regards, Guy
  #4 (permalink)  
Old August 30th, 2010, 12:12 PM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default RE: LINQ

Try this link brother,

http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx

there are very helpful examples here.

Rajeev Rajput.
  #5 (permalink)  
Old August 30th, 2010, 06:51 PM
Authorized User
Points: 160, Level: 3
Points: 160, Level: 3 Points: 160, Level: 3 Points: 160, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2004
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Rajeev,

That's exactly what I needed.

regards, Guy
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Alias all-or-nothing electrum BOOK: Beginning Microsoft SQL Server 2008 Programming ISBN: 978-0-470-25701-2 0 March 17th, 2009 04:42 PM
date formate in alias mateenmohd SQL Server 2000 1 November 7th, 2004 02:58 AM
Access alias question badgolfer Access 2 December 15th, 2003 04:47 AM
Access alias question badgolfer VB Databases Basics 1 December 12th, 2003 11:56 PM
The Alias Problem byterbit SQL Language 3 July 3rd, 2003 07:28 PM



All times are GMT -4. The time now is 10:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.