Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

DomainDataSource.DataView Error Add new Record RSS

6 replies

Last post Apr 13, 2011 10:54 PM by vrubel

(0)
  • DomainDataSource.DataView Error Add new Record

    Mar 24, 2010 05:34 PM | LINK

    Hello,

    When adding a new record in DomainDataSource, do the following:

     

    ((IEditableCollectionView) pessoaDomainDataSource.DataView). AddNew () as Teste.Web.Contexts.pessoa;
    
     

    But if not carry anything in the DataGrid before, the above statement fails! To resolve this, I'm calling the Load () method as follows:

     

     if (pessoaDomainDataSource.DataView.CanAdd == false)
                    pessoaDomainDataSource.Load ();
    
    
      

    Correct?

    Rogerio Bassete
    Brazil

  • mohnani.deepesh

    mohnani.deepesh

    Member

    677 Points

    137 Posts

    Microsoft

    Re: DomainDataSource.DataView Error Add new Record

    Mar 24, 2010 09:13 PM | LINK

    Could u elaborate more about your scenario. Thanks

    Deepesh Mohnani [MSFT]
    Program Manager
    twitter:@deepeshm
    blog: http://blogs.msdn.com/deepm

    ***This posting is provided "AS IS" with no warranties, and confers no rights ***
  • Re: DomainDataSource.DataView Error Add new Record

    Mar 25, 2010 11:40 AM | LINK

    OK, I´m sorry for short description.

     

    Code of DataGrid

     

            <riaControls:DomainDataSource AutoLoad="False" d:DesignData="{d:DesignInstance my:pessoa, CreateList=true}" Height="0" LoadedData="pessoaDomainDataSource_LoadedData_8" Name="pessoaDomainDataSource" QueryName="InvokeGetPessoasPorNomeQuery" Width="0" >
                <riaControls:DomainDataSource.DomainContext>
                    <my1:PessoasContext />
                </riaControls:DomainDataSource.DomainContext>
                <riaControls:DomainDataSource.QueryParameters>
                    <riaControls:Parameter ParameterName="nomePessoa" Value="{Binding ElementName=nomePessoaTextBox, Path=Text}" />
                </riaControls:DomainDataSource.QueryParameters>
            </riaControls:DomainDataSource>
            <StackPanel Height="30" HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Top">
                <sdk:Label Content="Nome Pessoa:" Margin="3" VerticalAlignment="Center" />
                <TextBox Name="nomePessoaTextBox" Width="566" />
                <Button Command="{Binding Path=LoadCommand, ElementName=pessoaDomainDataSource}" Content="Load" Margin="3" Name="pessoaDomainDataSourceLoadButton" />
            </StackPanel>
            <sdk:DataGrid AutoGenerateColumns="True" Height="141" HorizontalAlignment="Left" ItemsSource="{Binding ElementName=pessoaDomainDataSource, Path=Data}" Margin="85,36,0,0" Name="pessoaDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="602" IsReadOnly="True">
            </sdk:DataGrid>
            <Button Content="Alterar" Height="23" HorizontalAlignment="Left" Margin="168,183,0,0" Name="button3" VerticalAlignment="Top" Width="75" Click="button3_Click" />
            <Button Content="Inserir" Height="23" HorizontalAlignment="Left" Margin="85,183,0,0" Name="button4" VerticalAlignment="Top" Width="75" Click="button4_Click" />
            <Button Content="Excluir" Height="23" HorizontalAlignment="Left" Margin="249,183,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click_1" />
    
    

    DataGrid  make with DataSource Wizard, after add tree buttons for basic operations.

    In button1_Click_1 event, add o following code:

     

                ChildWindow1 frm = new ChildWindow1();
                frm.dataForm1.CurrentItem = ((IEditableCollectionView)pessoaDomainDataSource.DataView).AddNew() as SistemaWEB.Web.Contexts.pessoa;
                frm.Closed += new EventHandler(frm_Closed2);
                frm.Show();                 
    
    


    When no data is researched and calls the code above, the following error is posted "'AddNew' is not supported by this ICollectionView."

    But if I search for something before, nothing happens.

    Environment:

    Windows 7 Professional

    Visual Studio 2010 RC + SilverLight 4

    SilverLight 4 Tools

     

     

     

     

  • kylemc

    kylemc

    Contributor

    7243 Points

    1147 Posts

    Microsoft

    Re: DomainDataSource.DataView Error Add new Record

    Mar 25, 2010 06:05 PM | LINK

    This may be a framework bug. Until we determine how to fix the bug, you can use this workaround to avoid it.

    Set the QueryName in the contructor of your page and not in xaml.

    public MyPage()
    {
      InitializeComponent();
    
      this.pessoaDomainDataSource.QueryName = "InvokeGetPessoasPorNomeQuery";
    
      // ...
    }
    Kyle
  • sladapter

    sladapter

    All-Star

    43609 Points

    7910 Posts

    Re: DomainDataSource.DataView Error Add new Record

    Mar 25, 2010 06:12 PM | LINK

    You need to add the new Item to the DomainContext entity collection, not in the DataView:

    possoa p = new possoa();

    YourDomainContext.possoas.Add(p);

    frm.dataForm1.CurrentItem = p;
    If you only need to add item, not edit exiting items, you do not even need to call Load. 
     
    Sally Xu
    Software Engineer
    Aprimo, Inc

    Please remember to mark the replies as answers if they answered your question
  • kylemc

    kylemc

    Contributor

    7243 Points

    1147 Posts

    Microsoft

    Re: DomainDataSource.DataView Error Add new Record

    Mar 25, 2010 06:21 PM | LINK

    Actually you should be able to add the entity a number of places (DataForm, DomainDataSource.DataView, or DomainContext). The current limitation is due to a bug.

    Kyle

  • vrubel

    vrubel

    Member

    6 Points

    3 Posts

    Re: DomainDataSource.DataView Error Add new Record

    Apr 13, 2011 10:54 PM | LINK

    rogerio_bassete

    When no data is researched and calls the code above, the following error is posted "'AddNew' is not supported by this ICollectionView."

    should be the method "insert" for entity on the server side.

    [Insert]
    public void InsertBlaBla(BlaBla blaBla)
    {