Let’s say you’ve an entity that has a property typed as ICollection<string> and I want to store it as varchar in SQL Server in JSON format.
How to achieve this?
Thank you in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Probably You should have another string property in your Model class to hold the JSON represntation of the Collection of string. and that property will be mapped to your Table. Do not map the Collection property to your Table. Something like this
And Before saivng the data to your table, You need to fill the
JsonDataproperty value by reading theItemsPropert value.Bytheway, Are you sure you want to store the
JSONrepresentation in the table ? Why not use Master – details approach. store the JSON data into normalized tables. Whenever you want to build the JSON back, you can do it in C#.