Ask a questionAsk a question
 

AnswerCant update CollectionView based on ADO.Net Data Service

  • Wednesday, October 28, 2009 2:21 PMBoincer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I am using VS2010 beta 2 and have a solution with two projects. My "Data Service" project exposes a ADO.Net Data Service hooked up to an Entity Data Model:

    public class RoadmapperDataService : DataService<RoadmapperModelEntityContainer>
    {
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
        }
    }
    
    My "WPC Client" project has a service reference to the Data Service above. A data grid is bound to the data service:

        <Window.Resources>
            <CollectionViewSource x:Key="roadmapsViewSource" d:DesignSource="{d:DesignInstance my:Roadmaps, CreateList=True}" />
        </Window.Resources>
        <Grid DataContext="{StaticResource roadmapsViewSource}">
            <DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" Height="200" HorizontalAlignment="Left" ItemsSource="{Binding Mode=TwoWay}" Margin="12,12,0,0" 
                      Name="roadmapsDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="400">
                <DataGrid.Columns>
                    <DataGridTextColumn x:Name="roadmapIDColumn" Binding="{Binding Path=RoadmapID}" Header="Roadmap ID" Width="SizeToHeader" />
                    <DataGridTextColumn x:Name="roadmapNameColumn" Binding="{Binding Path=RoadmapName, Mode=TwoWay}" Header="Roadmap Name" Width="SizeToHeader" />
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
    
    and the code behind for the WPF window hosting this data grid:

    public partial class MainWindow : Window
    {
        private Uri svcUri;
        private RoadmapperModelEntityContainer context;
    
        public MainWindow()
        {
            svcUri = new Uri("http://localhost:10000/RoadmapperDataService.svc");
            context = new RoadmapperModelEntityContainer(svcUri);
    
            InitializeComponent();
        }
    
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            System.Windows.Data.CollectionViewSource roadmapsViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("roadmapsViewSource")));
            roadmapsViewSource.Source = context.Roadmaps;
        }
    }
    
    The window loads OK and displays data from the data service at runtime. However when I try to edit any data in the data grid I get an exception thrown: EditItem' is not allowed for this view.

    Can anyone assist? I have searched and searched for the answer to this one :-(


Answers

  • Tuesday, November 03, 2009 9:24 AMPhani Raju MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,
     The issue is that the Source property of the CollectionViewSource is being set to the DataServiceQuery type which only supports the IEnumerable interface and not the other interfaces required for Databinding to work.
    If you want binding support for UI controls in WPF or Silverlight applications , please look at the Databinding support we introduced in our latest CTP .

    Introduction to Data Binding in Silverlight 3 with CTP2
    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj

All Replies

  • Thursday, October 29, 2009 3:58 PMVitek Karas - MSFT Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Do you have a callstack for the exception (or at least its type)?
    Are you using views in your database?
    If this error comes from the server could you please capture the response the server sends? (for example using Fiddler or something similar).

    Thanks,
    Vitek Karas [MSFT]
  • Tuesday, November 03, 2009 9:24 AMPhani Raju MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,
     The issue is that the Source property of the CollectionViewSource is being set to the DataServiceQuery type which only supports the IEnumerable interface and not the other interfaces required for Databinding to work.
    If you want binding support for UI controls in WPF or Silverlight applications , please look at the Databinding support we introduced in our latest CTP .

    Introduction to Data Binding in Silverlight 3 with CTP2
    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj