コード例 #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);
            }
        }