I have a legacy code which I'm trying to change. This legacy code stores and retrieves data from local storage. I'm trying to change it to save data, specifically c# classes, in a postgres database. The way the legacy code stores data is this:
FileSerializer.Serialize<T>(filename, instance);
I know how to INSERT INTO a serializable java object in postgres but I can't find a tutorial on how to do it with a c# object.
Thanks for your time!
I ended up using Dapper as it supports ORM and postgres.
It's simple with NEntityDb . You can find samples of how to insert objects here .
using (DbInstance dbInstance = new DbInstance())
{
int rowsAffected = dbInstance.NonQueryOf<Customer>(new Customer
{
FirstName = "Clair",
LastName = "Guiet",
TaxCode = "3720045188",
Email = "cguiet@gov.uk",
BirthDate = new DateTime(1980, 4, 15),
Points = 10
})
.Insert()
.RowsAffected;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.