views:

1839

answers:

3

Still a bit new to Linq. This is driving me nuts. I want to alias a column, the alias should have a space.

This works fine:

Dim q = From tmp in t.Table Select iDate = tmp.iDate

But, I want this to work

Dim q = From tmp in t.Table Select "Some Alias With Space" = tmp.iDate

Any ideas?

A: 

As far as I know, you can't do this because columns alias must be valid C# identifiers, and they don't allow whitespaces.

eKek0
+2  A: 

First of all Alias's can't have spaces, just like any variable name can't have a space. My question tho is why would you want/need to have a space in your name? I'm sure there are better means of accomplishing what your trying to achieve with out trying to institute bad practices of bad naming conventions.

David Yancey
You can only have a space in your alias if you are using T-SQL, Select * from Mytable [My table Name]. But like david said, there is no point to having a space in your code. If you really needed to, use the _
Jason Heine
Thanks! The reason for looking for a space is b/c the data returned is in an IList"Return q.ToList"At this point I simply bind this to a rad grid. The grid column header takes the column names. I was looking for a simple approach for spaces in the column header on the grid.Knowing that alias can't have spaces I will modify the header manually. Thanks for the quick responses!
sugarcrum
A: 

You can't, sorry. Hell, if you bring a table with a space in the name into Linq it will automatically replace the space with underscores.

Besides it not being possible, it is an extremely overwhelmingly bad idea. Something that people that wrote Access should be shot because of.

Serapth