Beispiel #1
0
 /// <summary>
 /// Define a subdocument (or a list of) as a reference
 /// </summary>
 public EntityBuilder <T> DbRef <K>(Expression <Func <T, K> > property, string collection = null)
 {
     return(this.GetProperty(property, (p) =>
     {
         BsonMapper.RegisterDbRef(_mapper, p, collection ?? _mapper.ResolveCollectionName(typeof(K)));
     }));
 }
Beispiel #2
0
        public LiteCollection(string name, LazyLoad <LiteEngine> engine, BsonMapper mapper, Logger log)
        {
            _name     = name ?? mapper.ResolveCollectionName(typeof(T));
            _engine   = engine;
            _mapper   = mapper;
            _log      = log;
            _visitor  = new QueryVisitor <T>(mapper);
            _includes = new List <string>();

            // if strong typed collection, get _id member mapped (if exists)
            if (typeof(T) != typeof(BsonDocument))
            {
                var entity = mapper.GetEntityMapper(typeof(T));
                _id = entity.Id;

                if (_id != null && _id.AutoId)
                {
                    _autoId =
                        _id.DataType == typeof(ObjectId) ? BsonType.ObjectId :
                        _id.DataType == typeof(Guid) ? BsonType.Guid :
                        _id.DataType == typeof(DateTime) ? BsonType.DateTime :
                        _id.DataType == typeof(Int32) ? BsonType.Int32 :
                        _id.DataType == typeof(Int64) ? BsonType.Int64 :
                        BsonType.Null;
                }
            }
            else
            {
                _autoId = BsonType.ObjectId;
            }
        }