[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

linq query with ordered columns

Posted on 2011-09-30
4
Medium Priority
?
318 Views
Last Modified: 2013-11-11
I'm new to Linq and I'd like to rewrite the query I use to return results from a DomainService so that the columns are returned and a specific order.  If this was SQL I would use somthing like SELECT col1, col2, col3 from myTable.  The rows will be loaded into a datagrid in a Silverlight app.
public IQueryable<myTable> GetMyTable()
        {
            return this.ObjectContext.myTable.OrderBy(e => e.ItemID);
            
        }

Open in new window

0
Comment
Question by:PeterTrefren
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36893417
I'm not 100% on this, but have you tried switching the order of the properties as defined in your myTable class?
0
 
LVL 14

Expert Comment

by:binaryevo
ID: 36893490
Im not sure how you would do it with a datatable but, the syntax looks like this if you have a specific object your using:

var test = from t in myListFromDomainObject
                 select new BindingObjectThatICreated
                 {
                      ObjectVal = t.ObjectVal,
                      ObjectVal2 = t.ObjectVal2
                 }

Here are some pretty good basic examples:  http://msdn.microsoft.com/en-us/vcsharp/aa336756

Hope this helps, if you need more direction just let me know.

0
 

Accepted Solution

by:
PeterTrefren earned 0 total points
ID: 36920647
binaryevo: I tried your solution and was getting an error on return from the DomainService to get the data.  The following thread post http://forums.silverlight.net/p/119935/270919.aspx has what you're talking about as a solution but the person who posted points out a limitation of this kind of solution.  


For what I want to do, displaying columns in a specific order in a grid, the code I've attached works the best.




<riaControls:DomainDataSource Name="questionDataSource" LoadSize="20" QueryName="GetTestQuestions" AutoLoad="True">
                <riaControls:DomainDataSource.DomainContext>
                    <ds:QuestionContext></ds:QuestionContext>
                </riaControls:DomainDataSource.DomainContext>
            </riaControls:DomainDataSource>

            <sdk:DataGrid AutoGenerateColumns="True"  Name="dataGrid1" Width="Auto" Height="Auto" MinHeight="100" 
                          ItemsSource="{Binding Data, ElementName=questionDataSource}" VerticalScrollBarVisibility="Visible">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn Header="QuestionID" Binding="{Binding QuestionID}"  />

                    <!--Question-->
                    <sdk:DataGridTemplateColumn  Header="Question" >
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock TextWrapping="Wrap" Text="{Binding Question}" />
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>

                    <!--Ans1-->
                    <sdk:DataGridTemplateColumn  Header="Ans1" >
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock TextWrapping="Wrap" Text="{Binding Ans1}" />
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>

                    <!--Ans2-->
                    <sdk:DataGridTemplateColumn  Header="Ans2" >
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock TextWrapping="Wrap" Text="{Binding Ans2}" />
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>

                    <!--Ans3-->
                    <sdk:DataGridTemplateColumn  Header="Ans3" >
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock TextWrapping="Wrap" Text="{Binding Ans3}" />
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>

                    <!--Ans4-->
                    <sdk:DataGridTemplateColumn  Header="Ans4" >
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock TextWrapping="Wrap" Text="{Binding Ans4}" />
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>


                </sdk:DataGrid.Columns>
            </sdk:DataGrid>

Open in new window

0
 

Author Closing Comment

by:PeterTrefren
ID: 36941267
This provides the what I wanted.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question