Exemplo n.º 1
0
        public virtual DocumentReference AddItem(LiteDBv4.BsonDocument document)
        {
            LiteCollection.Insert(document);
            var newDoc = new DocumentReference(document, this);

            Items.Add(newDoc);
            return(newDoc);
        }
Exemplo n.º 2
0
 public DocumentReference(LiteDBv4.BsonDocument document, CollectionReference collection) : this()
 {
     LiteDocument = document;
     Collection   = collection;
 }
Exemplo n.º 3
0
        protected void Initialize(IEnumerable <LiteDBv4.BsonValue> bsonValues)
        {
            Source = bsonValues;

            if (bsonValues == null)
            {
                HasValue = false;
            }
            else
            {
                HasValue = true;

                var items = bsonValues as LiteDBv4.BsonValue[] ?? bsonValues.ToArray();

                if (bsonValues is LiteDBv4.BsonArray bsonArray)
                {
                    IsArray = true;
                    AsArray = bsonArray;
                    Count   = bsonArray.Count;
                }
                else if (items.Length == 1 && items[0].IsArray)
                {
                    IsArray = true;
                    AsArray = items[0].AsArray;
                    Count   = items[0].AsArray.Count;
                }
                else if (items.Length == 1 && items[0].IsDocument)
                {
                    var bsonDocument = items[0].AsDocument;
                    if (bsonDocument.ContainsKey(EXPR_PATH))
                    {
                        if (bsonDocument[EXPR_PATH].IsArray)
                        {
                            IsArray = true;
                            AsArray = bsonDocument[EXPR_PATH].AsArray;
                            Count   = bsonDocument[EXPR_PATH].AsArray.Count;
                        }
                        else
                        {
                            IsDocument = true;
                            AsDocument = new LiteDBv4.BsonDocument {
                                { @"value", bsonDocument[EXPR_PATH] }
                            };
                            Count = 1;
                        }
                    }
                    else
                    {
                        IsDocument = true;
                        AsDocument = items[0].AsDocument;
                        Count      = 1;
                    }
                }
                else
                {
                    IsArray = true;
                    AsArray = new LiteDBv4.BsonArray(items);
                    Count   = items.Length;
                }
            }
        }