How alias column name in LINQ?

  • Thread starter Thread starter Ronald S. Cook
  • Start date Start date
R

Ronald S. Cook

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