locked
create a new related entity from crm silverlight editable datagrid RRS feed

  • Question

  • Hi All,

    I am using sdk silverlight editable grid for data population.In the grid i am populating a related entity of the mainviewmodel entity using $expand odata query.

    Here if i edit the grid the data is saved to the database but creating a new record only created the main entity record not the related one.

     private void btnAdd_Click(object sender, RoutedEventArgs e)
            {
       
                New_vendorproduct vendorDetail = new New_vendorproduct();
             
               // vendorDetail.new_product_new_vendorproduct = new Product( new );
               
                TheProductViewModel.VendorProduct.Add(vendorDetail);
                 
                TheProductViewModel.SelectedVendorProduct = vendorDetail;
            
    
            }
    
     private void btnSave_Click(object sender, RoutedEventArgs e)
            {
                
                if (!this.DataGridPopup.IsValid)
                {
                    HtmlPage.Window.Alert("Please correct all validation errors before saving.");
                    return;
                }
                else
                {
                    try
                    {
                        BeginSaveChanges();
                    }
                    catch (SystemException se)
                    {
                        _syncContext1.Send(new SendOrPostCallback(showErrorDetails), se);
                    }
    
                }
    
            }
    
       private void BeginSaveChanges()
            {
                _ctx.BeginSaveChanges(OnSaveContactsComplete, TheProductViewModel.SelectedVendorProduct);
            }
    
            private void OnSaveContactsComplete(IAsyncResult result)
            {
                try
                {
                    _ctx.EndSaveChanges(result);
                  
                    HtmlPage.Window.Alert("Vendor product saved successfully");
                }
                catch (SystemException se)
                {
                    _syncContext1.Send(new SendOrPostCallback(showErrorDetails), se);
                }
            }
    
    here product is the related entity
    
    i queried through
    
     DataServiceQuery<New_vendorproduct> query = (DataServiceQuery<New_vendorproduct>)_ctx.New_vendorproductSet
                        .AddQueryOption("$expand", "new_product_new_vendorproduct")
                        .Where(c => c.new_product_new_vendorproduct.Name.StartsWith(str));
                        query.BeginExecute(RetriveVendorProductComplete, query);
    
    part of my xaml
    
    from expanded product by relation "new_product_new_vendorproduct"
    
     <sdk:DataGridTextColumn x:Name="mfgPart"
                                                Binding="{Binding Path=new_product_new_vendorproduct.New_manufacturernumber, Mode=TwoWay}"
                                                Header="Mfg. Part"
                                                Width="Auto"
                                                />
    
    from vendor product directly binded
    
                        <!--Description-->
                        <sdk:DataGridTextColumn x:Name="description"
                                                Binding="{Binding Path=New_vproductdescription,Mode=TwoWay}"
                                                Header="Description"
                                                Width="Auto" />


    Please help me.This is eating my head :(

    Thursday, September 27, 2012 10:16 AM