Try our conversational search powered by Generative AI!

DDS with nested types

Vote:
 

Hi!
I want to save some data with DDS, but keep having NotSupported exceptions when using linq querries.

I have done it with Entity Framework, but I wanted to migrate to Episerver API.

Is it even possible with the Episerver querry provider?

Code example:

    public class MyConfiguration
    {
        public int MyNumber { get; set; }
        public ICollection<MyPage> ChoosedPages { get; set; }
        public ICollection<MyLanguage> ChoosedLanguages { get; set; }
    }

    public class MyPage
    {
        public bool IsSelected { get; set; }
        public string GUID { get; set; }
    }

    public class MyLanguage
    {
        public bool IsSelected { get; set; }
        public string LanguageName { get; set; }
    }
    public class Testing
    {
        public void Test ()
        {
            var configuration = new MyConfiguration ()
            {
                MyNumber = 1,
                ChoosedPages = new List<MyPage> ()
                {
                    new MyPage()
                    {
                        IsSelected = true,
                        GUID = "aaaa"
                    },
                    new MyPage()
                    {
                        IsSelected = true,
                        GUID = "bbbb"
                    },
                    new MyPage()
                    {
                        IsSelected = false,
                        GUID = "cccc"
                    }
                },
                ChoosedLanguages = new List<MyLanguage> ()
                {
                    new MyLanguage()
                    {
                        IsSelected = true,
                        LanguageName = "en"
                    },
                    new MyLanguage()
                    {
                        IsSelected = false,
                        LanguageName = "sk"
                    },
                    new MyLanguage()
                    {
                        IsSelected = true,
                        LanguageName = "ru"
                    }
                }
            };

            using ( var store = DynamicDataStoreFactory.Instance.GetOrCreateStore(typeof( MyConfiguration ) ))
            {
                store.Save ( configuration );

                var config = store.Items<MyConfiguration> ()
                    .Include ( m=> m.ChoosedPages )
                    .FirstOrDefault ( m => m.MyNumber == 1 &&
                                           m.ChoosedPages.Any ( p => p.IsSelected ));
                if( config != null )
                    config.ChoosedLanguages = new List<MyLanguage>();
            }
        }
    }

This compiles, but throws 'Method 'Any' Not supported' exception.

Please help.

#203435
Edited, Apr 23, 2019 17:25
Vote:
 

See https://world.episerver.com/blogs/Jonas-Bergqvist/Dates/2010/3/Dynamic-Data-Store-LINQ-implementation--from-the-inside/

#203438
Apr 24, 2019 2:45
Vote:
 

Thanks Paul,

but I was not able to fix my problem with the link you have provided.

The blog post you provided is not about this particular problem.

The question in here is: How can i querry nested collections using DDS.

Using a different qyerry, based on the blog:

var config = (from myCon in store.Items<MyConfiguration>()
                    where myCon.MyNumber == 1
                    from myConChoosedPage in myCon.ChoosedPages
                    where myConChoosedPage.IsSelected
                    select myCon).ToList();

I still get 'The method 'SelectMany' is not supported' exception.

Getting all items from DDS and then quering them works:

var items = store.Items<MyConfiguration>()
                    .ToList()
                    .FirstOrDefault( item => item.MyNumber == 0 && 
                                             item.ChoosedPages.Any( y => y.IsSelected ));

But I dont want to load all items. I want to run the querry on the data in the database.

#203443
Edited, Apr 24, 2019 10:07
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.