[RavenDB] Object serialized to Array. JObject instance expected.

3,159 views
Skip to first unread message

Ales Vojacek

unread,
May 12, 2010, 6:19:39 AM5/12/10
to rav...@googlegroups.com
Hi all,
public class PhoneBook : ObservableCollection<PhoneBookEntry>
{
public String Id {get;set;}
}

public class PhoneBookEntry
{
public String Id { get; set; }
public String FirstName { get; set; }
public String LastName { get; set; }
public String PhoneNumber { get; set; }
public String Name { get; set; }
}


When I'm trying to save PhoneBook I got exception (subject)

phoneBook.Add(new PhoneBookEntry(){Name="Algida", FirstName="Ales",
LastName="Vojacek", PhoneNumber="+420603893335"});
phoneBook.Add(new PhoneBookEntry(){Name="Algida",
FirstName="Ales", LastName="Vojacek", PhoneNumber="+420608112158"});
phoneBook.Add(new PhoneBookEntry(){Name="Algida_Pokusnej",
FirstName="Ales", LastName="Vojacek", PhoneNumber="+420603893335"});
phoneBook.Add(new PhoneBookEntry(){Name="Algida_Pokusnej",
FirstName="Ales", LastName="Vojacek", PhoneNumber="+420608112158"});
using (var session = docStore.OpenSession())
{
session.Store<PhoneBook>(phoneBook);
session.SaveChanges();
}

Thank you A.

theouteredge

unread,
May 12, 2010, 6:50:13 AM5/12/10
to ravendb
What is the exception you are getting?

Just from looking at you code I'd imagine the double Id in both
PhoneBook and PhoneBookEntry could cause a problem.

Ayende Rahien

unread,
May 12, 2010, 6:54:07 AM5/12/10
to ravendb
The problem is that the entity inherit from ObservableCollection

Ayende Rahien

unread,
May 12, 2010, 7:02:06 AM5/12/10
to ravendb
Okay, I looked into this.
The problem is that you can't represent an entity like this using JSON. JSON can represent an array or a property bag, not both at the same time.
You need to define this as:

public class PhoneBook 
   {

       public String Id {get;set;}
       public ObservableCollection<PhoneBookEntry> Entries {get;set;}
   }

Ales Vojacek

unread,
May 12, 2010, 7:07:43 AM5/12/10
to rav...@googlegroups.com
Hi,
ok, but what are limitation of interit from?
Is that mean, that with Raven I do not need maping data to objects as
with RDBMS, except any situations (like class inherited from xy) .

May be I'm still missing something basic in RavenDB :-(
Sorry for really begginers questions :-(
A.

Ayende Rahien napsal(a):
> The problem is that the entity inherit from ObservableCollection
>
> On Wed, May 12, 2010 at 11:50 AM, theouteredge
> <an...@theouteredge.co.uk <mailto:an...@theouteredge.co.uk>> wrote:
>
> What is the exception you are getting?
>
> Just from looking at you code I'd imagine the double Id in both
> PhoneBook and PhoneBookEntry could cause a problem.
>
> On May 12, 11:19 am, Ales Vojacek <avoja...@gmail.com

Ayende Rahien

unread,
May 12, 2010, 7:12:42 AM5/12/10
to ravendb
See my other comment. The limitation is that the root entity cannot be IEnuemrable

Ales Vojacek

unread,
May 12, 2010, 7:19:12 AM5/12/10
to rav...@googlegroups.com
Oh,
great thank you.
So anything inherited from collection , anything with indexer and so on
cannot be Stored?
A.

Ayende Rahien napsal(a):

Ales Vojacek

unread,
May 12, 2010, 7:20:29 AM5/12/10
to rav...@googlegroups.com
Great :-)
You are faster then my questions are :-)
ThumbUP :-)
A.
Ayende Rahien napsal(a):
> See my other comment. The limitation is that the root entity cannot be
> IEnuemrable
>
> On Wed, May 12, 2010 at 12:07 PM, Ales Vojacek <avoj...@gmail.com
> <mailto:avoj...@gmail.com>> wrote:
>
> Hi,
> ok, but what are limitation of interit from?
> Is that mean, that with Raven I do not need maping data to objects as
> with RDBMS, except any situations (like class inherited from xy) .
>
> May be I'm still missing something basic in RavenDB :-(
> Sorry for really begginers questions :-(
> A.
>
> Ayende Rahien napsal(a):
> > The problem is that the entity inherit from ObservableCollection
> >
> > On Wed, May 12, 2010 at 11:50 AM, theouteredge
> > <an...@theouteredge.co.uk <mailto:an...@theouteredge.co.uk>
> <mailto:an...@theouteredge.co.uk <mailto:an...@theouteredge.co.uk>>>
> wrote:
> >
> > What is the exception you are getting?
> >
> > Just from looking at you code I'd imagine the double Id in both
> > PhoneBook and PhoneBookEntry could cause a problem.
> >
> > On May 12, 11:19 am, Ales Vojacek <avoja...@gmail.com
> <mailto:avoja...@gmail.com>

Ayende Rahien

unread,
May 12, 2010, 7:20:55 AM5/12/10
to ravendb
I think that indexer would actually work. You just can't save it if it implements IEnumerable 
Reply all
Reply to author
Forward
0 new messages