Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 29th, 2010, 08:09 PM
Authorized User
 
Join Date: Oct 2004
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
 
Old August 30th, 2010, 02:53 AM
Registered User
 
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.
 
Old August 30th, 2010, 06:21 AM
Authorized User
 
Join Date: Oct 2004
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
 
Old August 30th, 2010, 12:12 PM
Registered User
 
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.
 
Old August 30th, 2010, 06:51 PM
Authorized User
 
Join Date: Oct 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Rajeev,

That's exactly what I needed.

regards, Guy





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





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