Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2011
    Posts
    72

    RavenDB foreach with session.Query

    I have the classes:

    Code:
        public class Account
        {
            public string Id { get; set; }
            public string Name { get; set; }
            public string Password { get; set; }
            public IList<Character> characters { get; set; }
    
            public Account()
            {
                characters = new List<Character>();
            }
        }
    
        public class Character
        {
            public string Id { get; set; }
            public string Name { get; set; }
        }
    And I am able to save em into the database but when I want to view them doing:

    Code:
                    var accounts = session.Query<Account>();
    
                    foreach (var acc in accounts)
                    {
                        Console.WriteLine("Account: {0}", acc.Id);
                        Console.WriteLine("Name: {0}", acc.Name);
                        Console.WriteLine("Password: {0}", acc.Password);
                        Console.WriteLine("Characters: {0}", acc.characters.Count);
    
                        foreach (var charac in acc.characters)
                        {
                            Console.WriteLine("----------------------------");
                            Console.WriteLine("ID: {0}", charac.Id);
                            Console.WriteLine("Name: {0}", charac.Name);
                            Console.WriteLine("----------------------------");
                        }
                    }
    I get the next JsonSerializationException:
    Cannot deserialize JSON object into type 'System.String'.

    I am able to do: session.Query<Account>().Count();
    But not .ToList() and things like that.

    Thanks in advance !

    EDIT:

    Code:
                    var accounts = session.Advanced.LuceneQuery<Account>()
           .WaitForNonStaleResults().ToArray();
    Gives:
    Cannot deserialize JSON object into type 'System.String'. (same problem)
    Last edited by diedy; 02-19-2011 at 09:20 AM. Reason: Additional Information

  2. #2
    Join Date
    Jan 2011
    Posts
    72
    Found the problem, I started working on my own application and I was using the same object Account and it contained different data ! Silly me
    That's why it was not able to deserialize the string, cause it didn't contain one, if you are going to use different database management tools you need to put the Model classes in a DLL. (Not 100% sure someone please confirm)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •