Exemple #1
0
        public void ParameterizedEagerLoad([IncludeDataSources(true, TestProvName.AllSQLite)] string context, [Values("en", "de")] string lang)
        {
            var items = new Item[]
            {
                new Item {
                    Id = 1, Name = "Item 1"
                },
                new Item {
                    Id = 2, Name = "Item 2"
                }
            };

            var itemTexts = new ItemText[]
            {
                new ItemText {
                    ItemId = 1, Lang = "de", Text = "Item 1 german text"
                },
                new ItemText {
                    ItemId = 1, Lang = "en", Text = "Item 1 english text"
                },
                new ItemText {
                    ItemId = 2, Lang = "de", Text = "Item 2 german text"
                },
                new ItemText {
                    ItemId = 2, Lang = "en", Text = "Item 2 english text"
                },
            };

            using (new AllowMultipleQuery())
                using (var db = GetDataContext(context))
                    using (db.CreateLocalTable(items))
                        using (db.CreateLocalTable(itemTexts))
                        {
                            var query = db.GetTable <Item>().Select(item => new
                            {
                                item.Name,
                                Texts = item.ItemTexts.Where(x => x.Lang == lang).Select(itemText => new
                                {
                                    itemText.Lang,
                                    itemText.Text
                                }).ToArray()
                            }).ToArray();

                            var expected = items.Select(item => new
                            {
                                item.Name,
                                Texts = itemTexts.Where(x => x.ItemId == item.Id && x.Lang == lang).Select(itemText => new
                                {
                                    itemText.Lang,
                                    itemText.Text
                                }).ToArray()
                            }).ToArray();

                            AreEqualWithComparer(expected, query);
                        }
        }