This is a migrated thread and some comments may be shown as answers.

LINQ problem?

4 Answers 51 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Wolfshund
Top achievements
Rank 2
Wolfshund asked on 13 Feb 2012, 09:56 AM
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

4 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 15 Feb 2012, 11:06 AM
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 >>
0
Wolfshund
Top achievements
Rank 2
answered on 17 Feb 2012, 02:35 AM
Hi Deyan,

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

Kind regards,
Joerg
0
Accepted
Deyan
Telerik team
answered on 20 Feb 2012, 04:54 PM
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 >>
0
Wolfshund
Top achievements
Rank 2
answered on 21 Feb 2012, 03:37 AM
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

Tags
DataBoundListBox
Asked by
Wolfshund
Top achievements
Rank 2
Answers by
Deyan
Telerik team
Wolfshund
Top achievements
Rank 2
Share this question
or