soitgoes / LoveSeat

Bringing CouchDB and .NET little closer
Other
96 stars 50 forks source link

Having issues using generics #39

Closed jwdonley closed 12 years ago

jwdonley commented 12 years ago

Here's the code snippet I'm using:

ViewResult<CouchUserDocument> result = db.View<CouchUserDocument>("testing_users");

The 'Items' property of result has a null result. It seems the data did not deserialize into the CouchUserDocument object.

Here is result.RawString:

{
   "total_rows":1,
   "offset":0,
   "rows":[
      {
         "id":"org.couchdb.user:joe@jdonley83.com",
         "key":{
            "_id":"org.couchdb.user:joe@jdonley83.com",
            "_rev":"2-b1259ad3584f2ae18aced7cdddc7b8c2",
            "name":"joe@jdonley83.com",
            "type":"user",
            "Content-Type":"application/json",
            "roles":[
               "role1",
               "role2"
            ],
            "datecreated":null,
            "datemodified":null,
            "user_type":"testing",
            "user_name":"Joe",
            "testing_password":"HASHEDPASSWORD"
         },
         "value":null
      }
   ]
}
soitgoes commented 12 years ago

What version of couchdb are you using? On Sep 30, 2012 3:21 PM, "Joe Donley" notifications@github.com wrote:

Here's the code snippet I'm using:

ViewResult result = db.View("testing_users");

The 'Items' property of result has a null result. It seems the data did not deserialize into the CouchUserDocument object.

Here is result.RawString:

{ "total_rows":1, "offset":0, "rows":[ { "id":"org.couchdb.user:joe@jdonley83.com", "key":{ "_id":"org.couchdb.user:joe@jdonley83.com", "_rev":"2-b1259ad3584f2ae18aced7cdddc7b8c2", "name":"joe@jdonley83.com", "type":"user", "Content-Type":"application/json", "roles":[ "role1", "role2" ], "datecreated":null, "datemodified":null, "user_type":"testing", "user_name":"Joe", "testing_password":"HASHEDPASSWORD" }, "value":null } ] }

— Reply to this email directly or view it on GitHubhttps://github.com/soitgoes/LoveSeat/issues/39.

jwdonley commented 12 years ago

version 1.2.0

soitgoes commented 12 years ago

What does your CouchUserDocument look like? It has to have public properties.

If you would please include your code or a proof of concept and I'll be happy to take a look

On Sun, Sep 30, 2012 at 3:21 PM, Joe Donley notifications@github.comwrote:

Here's the code snippet I'm using:

ViewResult result = db.View("testing_users");

The 'Items' property of result has a null result. It seems the data did not deserialize into the CouchUserDocument object.

Here is result.RawString:

{ "total_rows":1, "offset":0, "rows":[ { "id":"org.couchdb.user:joe@jdonley83.com", "key":{ "_id":"org.couchdb.user:joe@jdonley83.com", "_rev":"2-b1259ad3584f2ae18aced7cdddc7b8c2", "name":"joe@jdonley83.com", "type":"user", "Content-Type":"application/json", "roles":[ "role1", "role2" ], "datecreated":null, "datemodified":null, "user_type":"testing", "user_name":"Joe", "testing_password":"HASHEDPASSWORD" }, "value":null } ] }

— Reply to this email directly or view it on GitHubhttps://github.com/soitgoes/LoveSeat/issues/39.

Martin Murphy Whiteboard-IT http://whiteboard-it.com (205) 910-0720

soitgoes commented 12 years ago

I re verified my unit tests on Couch 1.2. Create a user "Professor" with a Password of "Farnsworth" and try running the unit tests. Should_Persist_Property is passing for me.

If you believe something is wrong please either send me the code or contribute a test in order to reproduce the problem and I'll be happy to fix or attempt to address the confusion.

Thanks for using LoveSeat!

On Sun, Sep 30, 2012 at 9:45 PM, Martin Murphy < martin.murphy@whiteboard-it.com> wrote:

What does your CouchUserDocument look like? It has to have public properties.

If you would please include your code or a proof of concept and I'll be happy to take a look

On Sun, Sep 30, 2012 at 3:21 PM, Joe Donley notifications@github.comwrote:

Here's the code snippet I'm using:

ViewResult result = db.View("testing_users");

The 'Items' property of result has a null result. It seems the data did not deserialize into the CouchUserDocument object.

Here is result.RawString:

{ "total_rows":1, "offset":0, "rows":[ { "id":"org.couchdb.user:joe@jdonley83.com", "key":{ "_id":"org.couchdb.user:joe@jdonley83.com", "_rev":"2-b1259ad3584f2ae18aced7cdddc7b8c2", "name":"joe@jdonley83.com", "type":"user", "Content-Type":"application/json", "roles":[ "role1", "role2" ], "datecreated":null, "datemodified":null, "user_type":"testing", "user_name":"Joe", "testing_password":"HASHEDPASSWORD" }, "value":null } ] }

— Reply to this email directly or view it on GitHubhttps://github.com/soitgoes/LoveSeat/issues/39.

Martin Murphy Whiteboard-IT http://whiteboard-it.com (205) 910-0720

Martin Murphy Whiteboard-IT http://whiteboard-it.com (205) 910-0720

jwdonley commented 12 years ago

Sure, here's a bit more of the code. Hopefully it helps:

CouchDatabase db = _client.GetDatabase("_users");
db.SetDefaultDesignDoc("test_users");
ViewResult<CouchUserDocument> result = db.View<CouchUserDocument>("testing_users");

List<User> output = new List<User>();
foreach (CouchUserDocument item in result.Items)
{
     //
}

The interesting thing is that I am expecting 2 results, and I am getting 2 results. But both results are just null objects.

Here is the private internal class defined within the UserRepository:

        private class CouchUserDocument
        {
            public string _id { get; set; }
            public string name { get; set; }
            public string type { get; set; }
            public List<string> roles { get; set; }
            public string datecreated { get; set; }
            public string datemodified { get; set; }
            public string user_name { get; set; }
            public string testing_password { get; set; }
        }

Let me know if there's any more info I can give you.

soitgoes commented 12 years ago

CouchUserDocument needs to be public or it won't be accessible to anything but the class that contains it.

Also I would suggest going ahead and using DateTime since LoveSeat can serialize and deserialize to ISO8611 date format. Personally I would implment IBaseObject on your class since you are using all those properties it will allow you to use .Net Property conventions and still serialize to JSON conventions for all of your properties and allow you to have the property Id serialize to _id

Let me know if you have any questions. I good place to look for examples is the unit tests in the project.

Also I really like the repository model so check out those items in LoveSeat.Repositories. I think you'll be able to use them or draw some inspiration on how you might like to create your own.

Let me know if this solves your issue.

Thanks

-Martin

On Sun, Sep 30, 2012 at 10:47 PM, Joe Donley notifications@github.comwrote:

Sure, here's a bit more of the code. Hopefully it helps:

CouchDatabase db = _client.GetDatabase("_users"); db.SetDefaultDesignDoc("test_users"); ViewResult result = db.View("testing_users");

List output = new List(); foreach (CouchUserDocument item in result.Items) { // }

The interesting thing is that I am expecting 2 results, and I am getting 2 results. But both results are just null objects.

Here is the private internal class defined within the UserRepository:

    private class CouchUserDocument
    {
        public string _id { get; set; }
        public string name { get; set; }
        public string type { get; set; }
        public List<string> roles { get; set; }
        public string datecreated { get; set; }
        public string datemodified { get; set; }
        public string user_name { get; set; }
        public string testing_password { get; set; }
    }

Let me know if there's any more info I can give you.

— Reply to this email directly or view it on GitHubhttps://github.com/soitgoes/LoveSeat/issues/39#issuecomment-9021297.

Martin Murphy Whiteboard-IT http://whiteboard-it.com (205) 910-0720

jwdonley commented 12 years ago

Looks like that did the trick! Thank you so much for the help and the tips.