adospace / litedbpad

LinqPad driver for LiteDB
BSD 2-Clause "Simplified" License
64 stars 18 forks source link

'LiteDBPad.DumpableBsonDocument' does not contain a definition #4

Closed AlexHedley closed 5 years ago

AlexHedley commented 6 years ago

I can successfully connect to my db. The Tables are listed and I can view content, for example: AllComment.Take (100) Returns a Results table of IEnumerable<DumpableBsonDocument>

_id _type EntityId
00000000-0000-0000-0000-000000000000 00000000-0000-0000-0000-000000000000
...

If I try AllComment.Where (a => a._id == '00000000-0000-0000-0000-000000000000')

'LiteDBPad.DumpableBsonDocument' does not contain a definition for '_id' and no extension method '_id' accepting a first argument of type 'LiteDBPad.DumpableBsonDocument' could be found (press F4 to add a using directive or assembly reference)

I've added the References to the dll that contains the Comment class. I've added the Namespace.

Is there anything else I need to add?

adospace commented 6 years ago

DumpableBsonDocument is more or less a Dictionary<string,object> so you can go with something like: AllComment.Where(_ => _["_id"] == "00000000-0000-0000-0000-000000000000")

or better (as you actually use LiteDB engine): AllComments.FindOne("00000000-0000-0000-0000-000000000000")

AlexHedley commented 6 years ago

Thanks for the reply,

Unfortunately the Where returns (0 items) but at least it's not getting the error anymore,

FindOne

The name 'AllComments' does not exist in the current context

adospace commented 6 years ago

ok mine was just pseudo code, I suppose the issue is with the Guid type (I guess you used that type for the id). Please try with something like: AllComment.Where(_ => _["_id"] == Guid.Parse("00000000-0000-0000-0000-000000000000"))

and (Comments instead of All) Comments.FindOne(Guid.Parse("00000000-0000-0000-0000-000000000000"))

Please note that All is just a shortcut for .FindAll()

AlexHedley commented 6 years ago

Where

The call is ambiguous between the following methods or properties: 'LiteDB.BsonValue.operator ==(LiteDB.BsonValue, LiteDB.BsonValue)' and 'System.Guid.operator ==(System.Guid, System.Guid)'

FindOne

Cannot execute text selection: The best overloaded method match for 'LiteDB.LiteCollection.FindOne(LiteDB.Query)' has some invalid arguments Argument 1: cannot convert from 'System.Guid' to 'LiteDB.Query'

adospace commented 6 years ago

Errors seem pretty self-explaining... Have you tried some tests? like: AllComments.Where(_ => (Guid)_["UniqueId"] == Guid.Parse("00000000-0000-0000-0000-000000000000")) or Comments.FindOne(Query.EQ("UniqueId", Guid.Parse("00000000-0000-0000-0000-000000000000")))

AlexHedley commented 6 years ago

Comment.FindOne(Query.EQ("_id", Guid.Parse("00000000-0000-0000-0000-000000000000")))

Found the record, Thanks