satmisha
asked on
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.
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.
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..
Problem unclear
Do you want to pass entire controls to the database or just the values?
Why do you not want to pass different parameters?
Also to point out, that what ste5an is mentioning is absolutely correct. This is bad design.
From what I am understanding, this is the what you are expecting.
Note: For this to work, the sequence of the sql parameters and the values in the Generic list should match.
Do you want to pass entire controls to the database or just the values?
Why do you not want to pass different parameters?
Also to point out, that what ste5an is mentioning is absolutely correct. This is bad design.
From what I am understanding, this is the what you are expecting.
SqlCommand sqlcmd = new SqlCommand();
List<string> param = new List<string>();
foreach (var item in param)
{
sqlcmd.Parameters.Add(item);
}
Note: For this to work, the sequence of the sql parameters and the values in the Generic list should match.
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
aha, an EAV model. How do you read your entities (Employee)?
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.
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.
ASKER
Thanks guys.
ASKER