LINQ problem?

5 posts, 1 answers
  1. Wolfshund
    Wolfshund avatar
    50 posts
    Member since:
    Feb 2007

    Posted 13 Feb 2012 Link to this post

    Hi Telerik Team,

    I'm trying to set the Databound Listbox's item source (previously Listbox only) with a LINQ query from to related tables 'Tapes' & 'TapeRetires', PK and FK is TapeID, with this code:

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using PhoneApp4.Model;
    using System.Windows.Navigation;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
      
    namespace PhoneApp4
    {
        public partial class MainPage : PhoneApplicationPage, INotifyPropertyChanged
        {
            // Constructor
            public MainPage()
            {
                InitializeComponent();
      
                this.DataContext = this;
      
                if (allTapeRetireItems == null)
                    allTapeRetireItems = new ObservableCollection<TapeRetire>();
                // all
                var tTapeRetireItems = from tr in App.Context.TapeRetireItems
                                       join t in App.Context.TapeItems on tr.TapeID equals t.ID
                                       select tr;
      
      
                allTapeRetireItems = new ObservableCollection<TapeRetire>(tTapeRetireItems);
      
            }
      
            private ObservableCollection<TapeRetire> m_TapeRetireItems;
            public ObservableCollection<TapeRetire> allTapeRetireItems
            {
                get { return m_TapeRetireItems; }
                set
                {
                    if (value != m_TapeRetireItems)
                    {
                        m_TapeRetireItems = value;
                        NotifyPropertyChanged("AllTapeRetireItems");
                    }
                }
            }
      
      
            public event PropertyChangedEventHandler PropertyChanged;
            void NotifyPropertyChanged(string propertyName)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
      
      
        }
    }

    The Databound Listbox is filled with data from the TapeRetireItems(tr?), but I don't get the related
    TapeName from TapeItems(t) displayed. I think that either my LINQ query is totally wrong or I can't
    use/misuse a ObservableCollection as Itemsource? Or should I use
    ObservableCollection.ToList()?
    If I try this LINQ query with LINQPad everything works fine, so I'm confused!
    Any is hint or a better example is greatly appreciated!
    Thanks!
    Kind regards,
    Joerg
  2. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 15 Feb 2012 Link to this post

    Hi Joerg,

    Based on the code snippet that you're sending I cannot really determine the reason for the undesired behavior. Could you please share some further details or probably a demo project that we can use to reproduce the scenario on our side and thus be able to directly take a look at what's going on?

    Please note that in order to be able to attach your project, you will need to open a new support ticket.

    Thanks for your time.

    All the best,
    Deyan
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Wolfshund
    Wolfshund avatar
    50 posts
    Member since:
    Feb 2007

    Posted 16 Feb 2012 Link to this post

    Hi Deyan,

    thank you for your reply.
    As you suggested I created a support ticket with included code project.

    Kind regards,
    Joerg
  5. Answer
    Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 20 Feb 2012 Link to this post

    Hello Joerg,

    Could you please make sure that you have posted the ticket regarding this issue since I am not seeing it in our system?

    Regards,
    Deyan
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Wolfshund
    Wolfshund avatar
    50 posts
    Member since:
    Feb 2007

    Posted 20 Feb 2012 Link to this post

    Hello Deyan,
    thank you for your reply. I submitted the ticket last Thursday (Ticket-ID is 512864) and I got support from Valentin Stoychev. Problem also already solved! Thankfully, this helped me not only to proceed a large step with my app, I got also some good understanding of LINQ and Entity framework (I'm still no pro here ;-) at least better basics).
    Thank you very much for your assistance.

    Kind regards,
    Joerg

Back to Top
DevCraft banner