Exemplo n.º 1
0
        public T Find(int recordId, bool errorIfMissing = true)
        {
            using (var db = _db.OpenRead())
            {
                var coll = GetCollection(db);
                T   rec  = default(T);
                try
                {
                    rec = coll.FindById(recordId);
                }
                catch (UnauthorizedAccessException)
                {
                    if (!_db.DbPath.TryGrantEveryoneFullControl())
                    {
                        throw Locked.File(_db.DbPath);
                    }
                }

                if (rec == null && errorIfMissing)
                {
                    throw RecordNotFoundException.For <T>("Id", recordId);
                }

                return(rec);
            }
        }
Exemplo n.º 2
0
        public DataRow Get(Guid id)
        {
            var row = _databaseGateway.GetSingleRowUsing(_queryFactory.Get(id));

            if (row == null)
            {
                throw RecordNotFoundException.For("Formula", id);
            }

            return(row);
        }
 private static T DefaultOrThrow(string field, BsonValue value, bool errorIfMissing)
 {
     if (errorIfMissing)
     {
         throw RecordNotFoundException.For <T>(field, value);
     }
     else
     {
         return(default(T));
     }
 }
        public T Find(int recordId, bool errorIfMissing = true)
        {
            using (var db = _db.OpenRead())
            {
                var rec = GetCollection(db).FindById(recordId);

                if (rec == null && errorIfMissing)
                {
                    throw RecordNotFoundException.For <T>("Id", recordId);
                }

                return(rec);
            }
        }