Wayne Douglas - 395 - Oct 7, 2014

Hi, I’ve posted a question to SO. I’ve kind of answered it myself but still worried I’ve got something wrong.

http://stackoverflow.com/questions/26234186/servicestack-ormlite-upadte-child-collection

I’m concerned the parent table has the reference data as JSON in the column as well as it being added to the reference table.

Is this normal?

I see you’re comparing your example to an example that uses [Reference]'s which is why the behavior is different. By default all complex types are blobbed in OrmLite or you can use [Reference] to change this behavior see: https://github.com/ServiceStack/ServiceStack.OrmLite/#reference-support-poco-style

But honestly I find it’s hard to work out what the actual question is, what “doesn’t work” means, why the solution is ugly or what you’re expecting.

Wayne Douglas:

Well, in the docs it says you can set [reference] and in the referenced entity have {parent}Id property and then save the graph and ormlite sorts the relations and pushes them all to their respective tables.

My parent object is created further up the callstack. I want to update the parent object by adding some relational data.

You can’t do this by just calling update, I figured that out.

Now my question is; why is it storing JSON as well as the relational data in the reference table? I’m guessing the JSON isn’t automatically updated when the relational data is, if that’s the case then I don’t really want it. If it does then that’s amazing, I’ll keep it.

Basically there’s not a lot of docs on this. Particularly around updating collections. Any help appreciated as always.

A few things: db.Save() handles both Insert and Update, if you want to update references of a Poco its child collections needs to be marked with [Reference] and you’d need to use the db.Save(item,references:true) API. If you don’t include references:true it will only save the parent. If you only want to update the references on their own then you can use db.SaveReferences(parent, parent.childRefs) more info at: https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/tests/ServiceStack.OrmLite.Tests/LoadReferencesTests.cs#L235
To load a class with references you need to use db.LoadSelect(). It shouldn’t be both blobbing to the parent and saving to both the database. Can you publish the full source code that I can repro to: https://github.com/ServiceStack/Issues

Wayne Douglas:

Cheers - that explains a lot - I will try and look into what is happening with the blobbing but it is likely my lack of understanding