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?
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 annvarchar(max)
as it will be directly readable. A conversion tovarbinary
or something like that won't be useful.