C
C#3mo ago
cashen95

Serializing Config Section

I have a custom config section that i have built, and i am attempting to serialize it. My plan is to store the serialized section in SQL as a text column for retrieval later. What is the best way to accomplish this?
16 Replies
Angius
Angius3mo ago
Depends on the database In Postgres, I'd just use a Json column
cashen95
cashen95OP3mo ago
im using SQL, the part im struggling with (my fault i didnt explain) is the actual serialization of the config
Angius
Angius3mo ago
MySQL? MariaDB? SQLite? MSSQL? PostgreSQL?
cashen95
cashen95OP3mo ago
MSSQL on Azure
Angius
Angius3mo ago
It supports Json columns, so just use that Assuming you use EF for the ORM, it should be super simple
cashen95
cashen95OP3mo ago
yeah using EFCore heres the tricky part, the config is on a remote device and is sent as a the body of a service bus message
Angius
Angius3mo ago
Right, what is the config here? A plain text file? A structured JSON? XML? A binary file?
cashen95
cashen95OP3mo ago
xml, a custom section i wrote
Angius
Angius3mo ago
Ah, then probably not a json column Just store it as text IMO
cashen95
cashen95OP3mo ago
inherits from ConfigurationSection, which is supposed to have an XML serializer that i have not been able to make work
Angius
Angius3mo ago
I don't think there are any databases with XML columns... but if there ever was one, it would be Microsoft's But yeah, far as I can tell, just stuff it into a TEXT column
cashen95
cashen95OP3mo ago
i think you can just use text and store the xml as a json string then deserialize with Jsonconvert and be good im just having issues getting the config section to serialize
Angius
Angius3mo ago
You mean XML -> JSON -> save in JSON column?
cashen95
cashen95OP3mo ago
yeah
Angius
Angius3mo ago
Sure, that could work If you don't need to query it, I think plain text would still be fine tho
cashen95
cashen95OP3mo ago
nope no query needed, just need to pull that column, let Ef turn it back into the object then throw it into a message body and send it all the props i need to query are their own columns in SQL

Did you find this page helpful?