private static IQueryable <ContestEntity> DoQuery(ContestDataContext context, ContestQueryParameter query) { IQueryable <ContestEntity> set = context.QueryAllContests(); if (query.QueryByTitle) { set = ContestDataContext.QueryContestsByTitle(set, query.Title); } if (query.QueryByCreator) { set = ContestDataContext.QueryContestsByCreator(set, query.Creator); } if (query.QueryByStatus) { switch (query.Status) { case ContestStatus.Pending: set = ContestDataContext.QueryUnstartedContests(set); break; case ContestStatus.Running: set = ContestDataContext.QueryRunningContests(set); break; case ContestStatus.Ended: set = ContestDataContext.QueryEndedContests(set); break; default: throw new ArgumentException(nameof(query.Status)); } } return(set); }
/// <summary> /// 使用给定的比赛实体对象创建 ContestDataProvider 类的新实例。 /// </summary> /// <param name="context">数据上下文对象。</param> /// <param name="entity">比赛实体对象。</param> /// <param name="access">比赛数据底层访问对象。</param> /// <param name="isReadonly">一个值,该值指示当前对象是否为只读对象。</param> /// <exception cref="ArgumentNullException"/> private ContestDataProvider(ContestDataContext context, ContestEntity entity, bool isReadonly) { m_context = context ?? throw new ArgumentNullException(nameof(context)); m_entity = entity ?? throw new ArgumentNullException(nameof(entity)); m_access = new ContestAccessHandle(entity); m_readonly = isReadonly; m_disposed = false; }