2

I'm using MVC 5 Core on my Web API and I wanted to know what is the most optimal way of storing an Array into a database? Should I store Arrays, does it matter, or should I parse the array and input them individually into their own separate rows?

By optimally, I mean being able to have more control over the data and cutdown on load times. Should I be inputting Arrays into a database or parse them and put them in separate rows?

Database: MSSQL

This is my model code

 namespace backend.Models
{
 public class Portfolio
 {
 public string ProjectName { get; set; }
 public string ProjectRole { get; set; }
 public string ProjectTech { get; set; }
 public string[] ProjectDescriptions { get; set; }
 }
}
asked Nov 13, 2016 at 19:44
3
  • What do you mean by "optimal?" That is unanswerable unless you tell us what your specific criteria is. Commented Nov 13, 2016 at 19:54
  • Edited to be more accurate. Commented Nov 13, 2016 at 20:19
  • That's a classic 1:N data mapping. Any modern ORM can map that easily for you, even Linq2SQL. Commented Dec 14, 2016 at 19:23

2 Answers 2

2

(Assuming you have an RDB) You should create another table and put each array item in it as a row.

Don't try and reinvent the wheel with xml columns or string parsing. The RDB is designed to store and retrieve this kind of data as related tables.

answered Dec 14, 2016 at 16:10
0

Portfolio has a one to many relationship with ProjectDescriptions. That's the structured database way to look at this. You can hack around that in a multitude of ways but if you want to be friendly to a structured SQL database that's the deal.

There are other kinds of DB's that don't even have rows but MSSQL isn't one of them.

Load times aren't going to care about structure as much as amount of data. As for control, my watchword is readability.

answered Nov 13, 2016 at 20:08
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.