Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

How alias column name in LINQ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ronald S. Cook - 04 Feb 2008 15:51 GMT
Hi..

Does anyone know how to alias a column name in LINQ.  I.e. like putting "AS
DiagnosisType" after a column in a select statement in SQL?

Return From d In dc.Diagnosis _
Where d.Lookup.LookupCode <> "INA" _
Select d.DiagnosisId, _
d.DiagnosisName, _
d.DiagnosisCode, _
d.Lookup1.LookupValue _   <<<--- Here is where I want "AS DiagnosisType"
Order By DiagnosisName

Thanks,
Ron
Marc Gravell - 04 Feb 2008 16:10 GMT
Well, you could try aliasing via a projection? i.e. in your LINQ, doing
something like:
               select new {
                   p.MyCharColumn, // default name
                   Bar = p.Foo // aliased
               };

However! The aliases that it uses in the SQL are largely an implementation
detail. As far as I can see, it would be perfectly reasonable for the LINQ
provider to use "c0", "c1", "c2" etc for the columns: as long as it can map
them back to the members in your object model it is none of our business how
it handles it (encapsulation).

IIRC, from inspection I believe LINQ-to-SQL tends to honour aliases, but I
doubt it is guaranteed; what DbLinq does is anyones guess.

Marc
Marc Gravell - 04 Feb 2008 16:17 GMT
don't ask me how to map that to VB; 'tis a C# forum... as an outside guess:

Select d.DiagnosisId,
d.DiagnosisName,
d.DiagnosisCode,
DiagnosisType = d.Lookup1.LookupValue

also - ignore my DbLinq comment; I thought (incorrectly) that this was part
of a chain involving DbLinq - apologies for any confusion...

Marc
Marc Gravell - 04 Feb 2008 16:28 GMT
a lucky guess apparently... (or rather: the syntax is sensibly similar
between VB and C#)

http://community.bartdesmet.net/blogs/bart/archive/2007/09/05/visual-basic-9-0-f
eature-focus-linq-queries.aspx


Marc
Ronald S. Cook - 04 Feb 2008 16:46 GMT
Thanks Marc!

>a lucky guess apparently... (or rather: the syntax is sensibly similar
>between VB and C#)
>
> http://community.bartdesmet.net/blogs/bart/archive/2007/09/05/visual-basic-9-0-f
eature-focus-linq-queries.aspx

>
> Marc

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.