locked
Microsofts CRMOData example RRS feed

  • Question

  • I am trying to modify Microsofts OData example in the SDK to populate the combobox with quote numbers and in a new datagrid show the quote details - eventually I want to add data to the Quote.

    Anyway have modified the MainPage.xaml view as I figured this would update the html file, however it doesn't, so a very simple question how do I modify the views or the html page in the examples?

    Matt

    Tuesday, January 28, 2014 11:37 AM

All replies

  • Hi,

    I am really stuck with this...

    I have the following code:

     private void cmb_Quotes_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                try
                {
                    DataServiceQuery<Quote> query = (DataServiceQuery<Quote>)_context
                        .QuoteSet.Where<Quote>(a => a.Name == (string)cmb_Quotes.SelectedItem);
    
                    query.BeginExecute(OnRetrieveQuotessComplete, query);
                }
                catch (DataServiceQueryException dsqe)
                {
                    _syncContext.Send(new SendOrPostCallback(showErrorDetails), dsqe);
                }           
            }
    
            private void OnRetrieveQuotessComplete(IAsyncResult result)
            {
                try
                {
                    DataServiceQuery<Quote> results =
                        result.AsyncState as DataServiceQuery<Quote>;
    
                    Quote retrievedQuoteDetail = new DataServiceCollection<Quote>(results
                        .EndExecute(result))..First<Quote>();
                    
                    BeginRetrieveQuoteDetail(retrievedQuoteDetail.QuoteId);               
                }
                catch (SystemException se)
                {
                    _syncContext.Send(new SendOrPostCallback(showErrorDetails), se);
                }
            }
    
    
    
            private void BeginRetrieveQuoteDetail(Guid Id)
            {
                try
                {
                    DataServiceQuery<QuoteDetail> query = (DataServiceQuery<QuoteDetail>)_context
                        .QuoteDetailSet.Where<QuoteDetail>(a => a.QuoteId  == Id);
    
                    query.BeginExecute(OnRetrieveQuoteDetailComplete, query);
                }
                catch (DataServiceQueryException dsqe)
                {
                    _syncContext.Send(new SendOrPostCallback(showErrorDetails), dsqe);
                }
            }
           
            private void OnRetrieveQuoteDetailComplete(IAsyncResult result)
            {
                try
                {
                    DataServiceQuery<QuoteDetail> results =
                        result.AsyncState as DataServiceQuery<QuoteDetail>;
    
                    QuoteDetail retrievedQuoteDetail = new DataServiceCollection<QuoteDetail>(results
                        .EndExecute(result)).First<QuoteDetail>();
    
                    MessagePanel.Children.Add(new TextBlock()
                    {
                        Text =
                            String.Format("Retrieved the quote detail \"{0}\".",
                            retrievedQuoteDetail.Description)
                    });
    
                }
                catch (SystemException se)
                {
                    _syncContext.Send(new SendOrPostCallback(showErrorDetails), se);
                }
            }

    The first query was added to check it was returning the correct GUID, which it does.

    The second query was set up to retrieve the quote details for that guid.

    If the line is set as 

                    DataServiceQuery<QuoteDetail> query = (DataServiceQuery<QuoteDetail>)_context
                        .QuoteDetailSet.Where<QuoteDetail>(a => a.QuoteId  == Id);

    it doesn't like QuoteId saying "Operator '==' cannot be applied to operands of type 'EntityReference' and 'System.Guid'"

    If I set it to a.QuoteDetailId it allows it but obviously that is not returning the data I want.

    So what do I do?

    regards,

    Matt

    Thursday, February 13, 2014 11:26 AM
  • Any help?

    Matt

    Monday, February 17, 2014 10:38 AM
  • I have got it to retrieve the quote details based on a quote id:

     private void BeginRetrieveQuoteDetail(Guid Id)
            {
                dataGrid1.ItemsSource = null;
    
                _context = new AnconTestContext(ODataUri);
    
                lstQuoteDetails = new DataServiceCollection<QuoteDetail>(_context);
    
                var result = _context.QuoteDetailSet
                                    .Where<QuoteDetail>(r => r.QuoteId.Id == Id);
    
                lstQuoteDetails.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(lstQuoteDetails_LoadCompleted);
                lstQuoteDetails.LoadAsync(result);
    
            }
    
            private void lstQuoteDetails_LoadCompleted(object sender, LoadCompletedEventArgs e)
            {
                if (lstQuoteDetails.Continuation != null)
                {
                    lstQuoteDetails.LoadNextPartialSetAsync();
                }
                else
                {
                    dataGrid1.ItemsSource = lstQuoteDetails;
                }
    
            }

    How can I just return selected fields rather than the entire set of data?

    regards,

    Matt

    Thursday, February 20, 2014 2:22 PM