I've been getting an error when calling db.Users.FindById(x) where x points to an id that can't be found. I was expecting it to return null, but instead I was seeing an exception due to the .ToDictionary() extension being called on a null document instance.
I've put a null check on the .ToDictionary() call and added a few tests to cover the expected behaviour when no data can be found (i.e. null for FindById and empty collections for FindAllByX).
The problem might be more than I've trivially looked into, but I hope this helps.
Hi Craig,
I've been getting an error when calling
db.Users.FindById(x)
where x points to an id that can't be found. I was expecting it to returnnull
, but instead I was seeing an exception due to the.ToDictionary()
extension being called on anull
document instance.Your original test (https://github.com/craiggwilson/Simple.Data.MongoDB/blob/master/Simple.Data.MongoDBTest/FindTests.cs#L26) passes because the data can be found, but it wasn't returning
null
when the database was empty or the result couldn't be found (i.e. invalid id).I've put a
null
check on the.ToDictionary()
call and added a few tests to cover the expected behaviour when no data can be found (i.e.null
forFindById
and empty collections forFindAllByX
).The problem might be more than I've trivially looked into, but I hope this helps.