0

I have a database with a table named "Article" (containing all my articles of course) and another table named "ArticleSupplier" (containing supplier for my articles). Each article can have multiple suppliers.

What I do, is binding my table article to a WPF listview using Linq, but I also need to show the first supplier reference for my articles, so I did a binding of that kind :

DisplayMemberBinding="{Binding Path=ArticleSupplier[0].reference, Mode=OneWay}"

This work well, except for the performance, the scrolling is a real pain, certainly due to the amount of "sub-queries" that my binding involve.

How can I achieve this in a fastest way ? I really need to show the supplier reference in my listview (without that binding the scrolling performance are really good).

Thank a lot for your help, I am really stuck with this.

Karnalta
  • 518
  • 1
  • 9
  • 24

2 Answers2

0

You can eagerly load the data ahead using Include, so it will be a one time hit and the scrolling performance will not be affected.
If the additional time the loading will take will be an issue, either employ BackgroundWorker for loading or a similar technique.

You can filter only the first entity in reference using EF 4.1 functionality - like this C# Entity Framework 4.1 Lambda Include - only select specific included values

Community
  • 1
  • 1
Honza Pačuta
  • 317
  • 6
  • 18
  • Can you explain a little more the EF 4.1 solution ? I tried to include the EF 4.1 extention in my project and add the "Include("ArticleSupplier")" method to my query but it doesn't change anything in term of performance. – Karnalta Jun 29 '11 at 07:35
  • I think you can stick with you solution for now :), thumbs up. – Honza Pačuta Jun 29 '11 at 11:31
0

I solved my issue with the following method :

I added a custom field in my Article linq class called firstReference, I then altered my linq query so it now look like this :

            var articlesQuery = from art in QueryDataContext.Article
                                join artSup in QueryDataContext.ArticleSupplier on art.uid equals artSup.uidArticle
                                            select new
                                            {
                                                Article = art,

                                                firstSupplierUid = artSup.uid,
                                                firstReference = artSup.reference,
                                                firstFormat = artSup.format,
                                            };

And in my XAML binding, instead of binding on "ArticleSupplier[0].reference" I simply bind on "firstReference".

It seem to do the job pretty well.

Karnalta
  • 518
  • 1
  • 9
  • 24