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
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