Storing complex objects through stored procedures

357 views Asked by At

I have a complex object which includes multiple objects through composition.
What is a recommended way to persist such an object into database?

User{
name:
DOB:
address:{
street:
zipcode:
}
accounts:[
{accountId:"",bank:""},
{accountId:"",bank:""}
]
...
}

Do note the collections which form part of the object.
This entity would map to multiple tables in the database - user,address,account....

What is the recommended way to interact with a stored procedure for this kind of a data structure?

1

There are 1 answers

0
Ionic On

You have two options.

You can send the data as xml to your server and directly save this into an xml column.

You can store it in an nvarchar column with a specified limit (e.g. nvarchar(1000)) if possible. Otherwise store it into an nvarchar(max) as it will be directly readable. A conversion to varbinary or something like that won't be useful.