Open 0verflux opened 4 years ago
Can you provide some sample? Minimal code to run and reproduce the issue.
@FDemin Can you also provide us with some extra information like which version of LiteDB that you're using and which OS that you're trying to run it on?
having a property name Id
works on auto-incrementing
however, having a different property name (ID
, <Model Name>ID
), even having a [BsonId]
attribute, auto-increment doesn't work
@FDemin Auto-id only supports types Int32
, Int64
, ObjectId
and Guid
. In fact, the BSON spec doesn't even support UInt64
as a valid type for an element in a BSON (our serializer converts it to Int64
).
Question about this.
I've tested it with Id
as a long
and I can see it creates a json object instead of a number.
If I use int
, it creates a number.
Both seems to auto-increment correctly, but.. how do I get to use the long as a number and not as an object with a number embedded?
See the following snapshot of a sample ran first with long
and then with int
@sunnyatticsoftware LiteDB uses BSON serialization when storing data, which means that, internally, both int32
and int64
are stored in binary form. However, BSON is a superset of JSON – JSON only has a "number" type, while BSON has distinct types for int32
, int64
, double
and decimal
. So, in order to preserve the type of the value when converting a BSON to JSON, we use custom formats:
int32
is represented by number with no decimal places (e.g.: 3
);double
is represented by a number with decimal places (e.g.: 3.0
);int64
is represented by a document with the following structure: {"$numberLong":"3"}
decimal
is represented by a document with the following structure: {"$numberDecimal":"3"}
If you want to display only the numerical value of longs, you could do something like this: SELECT INT32($._id), Type, ... FROM events
.
using
ulong
as datatype for ID does not increment, and results with an exception.