Linq Select Using a Column Number

Is there a way using Linq to SQL that I can alias a data member using an ordinal number ?

Dim query1 = From q In source Select q.dogName, q.dogType
Dim query2 = From q In source Select q.fishColor, q.fishSize

pseudo..

Dim data = From d In query Select column1= d.DataMember(1), column2=d.DataMember(2)

Basically I'm trying to get (and alias) the first two columns of the source query without having to specify their names.

Hope that makes sense.
WatersideAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Prakash SamariyaIT ProfessionalCommented:
//This is will get first two column names
var columnnames = (from t in typeof(<table_name>).GetProperties() select t.Name).Take(2)

//Join them in string
string cols =   "new("+String.Join(",",columnnames)+")"

//Use that cols string in select to make Dynamic LINQ2SQL query
Dim data = From d In <table_name> Select(cols)

For more detail about Dynamic LINQ please refer:
http://weblogs.asp.net/scottgu/dynamic-linq-part-1-using-the-linq-dynamic-query-library
0
WatersideAuthor Commented:
I can't use Dynamic Linq as I'm writing for Windows Phone :(
0
Fernando SotoRetiredCommented:
I can not think of a way to do this because Linq to SQL and Linq to Entity Framework work from a model which have names to map to the database. When you write a Linq query you need to use those name otherwise the T-SQL query could not be constructed so that it could be sent to the server for execution.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.