开发者

Speedup Wpf & Linq binding on multiple table?

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 开发者_Go百科lot for your help, I am really stuck with this.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜