Need tutorial for saving POCO objects
Closed this issue · 5 comments
I don't see any document or test to create POCO objects. I have a hard time saving them. It only saves the id and rev and no other properties. I am sure I am doing something wrong but it would be nice to have a simple tutorial or document to do this kind of basic operation. Thanks!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LoveSeat;
using Newtonsoft.Json;
namespace ConsoleApplication1
{
public class Row:Document
{
[JsonProperty("Type")]
public string Type;
}
class Program
{
static void Main(string[] args)
{
var client = new CouchClient("somedomain.iriscouch.com", 80, "username", "password");
var db = client.GetDatabase("database");
Row r = new Row();
r.Type = "222";
r.Id = Guid.NewGuid().ToString();
db.CreateDocument(r); // Type isn't saved. only id and rev is saved.
}
}
}
Love seat only looks at properties. Not member variables. Trypublic string Type { get; set;} from my HP TouchPadOn Oct 3, 2011 7:34 PM, Chang Luo reply@reply.github.com wrote: I don't see any document or test to create POCO objects. I have a hard time saving them. It only saves the id and rev and no other properties. I am sure I am doing something wrong but it would be nice to have a simple tutorial or document to do this kind of basic operation. Thanks!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LoveSeat;
using Newtonsoft.Json;
namespace ConsoleApplication1
{
public class Row:Document
{
[JsonProperty("Type")]
public string Type;
}
class Program
{
static void Main(string[] args)
{
var client = new CouchClient("somedomain.iriscouch.com", 80, "username", "password");
var db = client.GetDatabase("database");
Row r = new Row();
r.Type = "222";
r.Id = Guid.NewGuid().ToString();
db.CreateDocument(r); // Type isn't saved. only id and rev is saved.
}
}
}
--
Reply to this email directly or view it on GitHub:
https://github.com/soitgoes/LoveSeat/issues/12
Thanks for the idea. But adding get and set makes no difference to me. I am on .NET4 + VS 2010.
I've redone CreateDocument a bit. I think you'll like it more now.
Please refer to CouchClientTest if you have any questions on how things work.
You're example above if you use a property instead of a field on the new version works.
Finally working now. Thanks for the quick fix!
Oh and FYI. Don't inherit from Document for your POCO. If you want a starting point that has Id and Rev on it Imlpement IBaseObject instead.
Any type of object that has looping properties such as JObject, XMLDocument, etc, should be avoided because they cause the JsonConvert.SerializeObject to crash.