How to databind results of LINQ query from ADO.Net Entity Framework with DataGrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Toucki
    New Member
    • Oct 2010
    • 1

    How to databind results of LINQ query from ADO.Net Entity Framework with DataGrid

    Hi.
    I have SQL Server database that is connected to my WPF desktop-based application via ADO.NET Entity Framework.

    Now I need get content of one of the table via LINQ query and show it in DataGrid control. Also, I need to let user to edit or delete data from DataGrid and update my database according this change.

    Here is a LINQ query:
    Code:
    from d in App.glidusContext.tbl_users
    select new { d.userID, d.userName, d.userPassword }
    My DataGrid code:
    Code:
    <DataGrid x:Name="ContentDataGrid">
       <DataGrid.Columns>
          <DataGridTextColumn Header="User ID" />
          <DataGridTextColumn Header="User Name" />
          <DataGridTextColumn Header="Password" />
       </DataGrid.Columns>
    </DataGrid>
    As I understand I have to use DataBinding mechanism and set DataContext, ItemSource, Mode etc.

    I tried a lot of examples from the Internet but most of them don't show how to make it with LINQ query, as result my application fails with InvalidOperatio nException.

    Please, help me with this functionality, this issue really confused me and stops my project.

    Thanks.
Working...