How to Pass object having values to Sql store procedure using Asp.Net MVC C#

Hi Experts,

I have an object containing lots of public values ( dropDown,checkbox, radioButton, txtBox etc..) that I want to send across to sql store procedure. Could you please provide some sample code to achieve this in ASP.Net MVC using c# ?

I know there is simple way exists where you can pass on different parameters that I want to avoid.
satmishaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

satmishaAuthor Commented:
Just to add that the object that I have used is of Type 'System.Collections.Generic.List'. Appreciate your early reply.
0
ste5anSenior DeveloperCommented:
I have an object containing lots of public values [..]
Bad design.

[..] I want to send across to sql store procedure [..]
Why? A relational database is not an object store. So this is not possible.

Thus:
What is your use-case? Any actual problem?

But, your wording sounds like you may have already some serious architectural problems..
1
satmishaAuthor Commented:
Thanks experts and apologies for putting less info. Let me try to put full perspective now.

Yes, Architecture is extremely poor of this as this is migration application.

Lets say you have an 'Employee' Model in MVC application and this Employee Model is consist of many values like

Class Employee
{
      Name
      Code
      Region
      Country
      Salary
}

In db you have table called  StorageTable having following columns

ID
Feature
FeatureValue

So what I am expecting is to push Employee model mentioned above in the StorageTable, so my final table would become like:

ID      Feature      FeatureValue
1      Name      Tom
1      Code      101
1      Region      Ch
1      Country      USA
1      Salary       20,000
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

pcelbaCommented:
Create a method which will store all the necessary property values into a string with defined separators and pass the string to the SP.  

If you decide the string format can be either XML or JSON then you may use XMLSerializer (https://docs.microsoft.com/en-us/dotnet/standard/serialization/examples-of-xml-serialization) or JavaScriptSerializer (https://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer(v=vs.110).aspx)

Of course, any serialization will extend the amount of data stored/processed on SQL Server but SQL Server can work with XML directly.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ste5anSenior DeveloperCommented:
aha, an EAV model. How do you read your entities (Employee)?
0
pcelbaCommented:
Just a note:
The data model containing
ID
Feature
FeatureValue
seems to be universal for any data but you have to also think about data queries from such model. Such queries is not easy to optimize and if you decide to have each feature value in its own column on the query output then it results in a bunch of LEFT JOINS.

Of course if we are talking about thousands of rows then the speed does not matter but millions of rows is something different.

And that was the reason ste5an is asking "How do you read your entities (Employee)?".

So we may continue in the discussion or close the question.
0
satmishaAuthor Commented:
Thanks guys.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.