Home Forums WPF controls Xceed DataGrid for WPF New to using the 2.0 DataGrid, using LINQ example

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26190 |

    I just started using the DataGrid and am trying to use LINQ to SQL. I have absolutely everything working EXCEPT for the SubmitChanges(). Nothing ever gets written back to the database.

    The code is pretty much from the help example. I will post the subset of the example that applies.

    XAML:
    <Grid.Resources>
    <xcdg:DataGridCollectionViewSource x:Key=”cvs_Outages”
    Source=”{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}},
    Path=OutageQuery}”/>
    </Grid.Resources>

    <my:DataGridControl Name=”dgOutages” ItemsSource=”{Binding Source={StaticResource cvs_Outages}}” SelectionMode=”Single” NavigationBehavior=”RowOnly” AutoCreateColumns=”False” EditTriggers=”BeginEditCommand, ClickOnCurrentCell, SingleClick, ActivationGesture” ItemScrollingBehavior=”Immediate” CellEditorDisplayConditions=”None”>

    C#:
    private DataLINQDataContext dl = new DataLINQDataContext();
    private IEnumerable m_query = null;
    public Customer cust;

    public IEnumerable OutageQuery
    {
    get
    {
    if (m_query == null)
    {
    m_query = from o in dl.Outages where o.custName == cust.custName select o;
    }
    return m_query;
    }
    }

    private void SaveModifications(object sender, RoutedEventArgs e)
    {
    dl.SubmitChanges();
    }

    The data in the grid updates correctly, however on the dl.SubmitChanges(); nothing is ever written to the database. I think I’m missing something fundamental here, but I have not been able to determine what it is. It appears to me that the itemssource is no longer associated with the DataLINQDataContext.

    Sorting, Grouping, custom edit controls are all working fine.

    Forgive me if this is something that has come up previously, but I didn’t see anything on the forums that applied to this simple example.

    Imported from legacy forums. Posted by Michael (had 4156 views)

    User (Old forums)
    Member
    Post count: 23064

    One additional item.

    Is there any way to loop through the .Row objects checking the isDirty flag and then manually use the data to update the LINQ table? I can loop through the .Items, but I can’t find a way to go through the .Row objects.

    Imported from legacy forums. Posted by Michael (had 328 views)

    Xceed Support
    Member
    Post count: 5658

    I tested the LinqToSql examples included in the dcoumentation and the SubmitChanges worked fine. Is it possible that there are conflicts when you try to submit the changes? If so, you could trying using the overload of the SubmitChanges method that takes a ConflictMode enumeration as a parameter to see if it makes a difference.

    It is not posisble to iterate through the DataRow collection to verify the IsDirty property since DataRows are containers for data items (System.Data.DataRow) and only exist if the data item is visible in the view port.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 223 views)

    User (Old forums)
    Member
    Post count: 23064

    Just a quick update on this.

    The issue was in the SQL server table that I was using. I was testing on a copy of a table that turned out NOT to have the primary key set. Once the key was set the updates worked fine.

    It was odd that no error was thrown by the data context.

    Imported from legacy forums. Posted by Michael (had 360 views)

    User (Old forums)
    Member
    Post count: 23064

    Is there a full working sample of Linq with Grid. I am not able to find.

    Thanks
    Aravind

    Imported from legacy forums. Posted by rvindh (had 217 views)

    Xceed Support
    Member
    Post count: 5658

    In the “Providing Data” section, you will find 3 LINQ examples.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 4936 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.