private IQueryable<ProjectUserMember> Fetch(
Csla.Data.ObjectContextManager<ApplicationEntities> ctx,
ProjectUserMemberDataCriteria criteria)
{
IQueryable<ProjectUserMember> query = ctx.ObjectContext.ProjectUserMembers
.Include("Project")
.Include("User")
.Include("CreatedByUser")
.Include("ModifiedByUser");
if (criteria.ProjectUserMemberId != null)
{
query = query.Where(row => row.ProjectUserMemberId == criteria.ProjectUserMemberId);
}
if (criteria.ProjectId != null)
{
query = query.Where(row => row.ProjectId == criteria.ProjectId);
}
if (criteria.RoleId != null)
{
query = query.Where(row => row.RoleId == criteria.RoleId);
}
if (criteria.UserId != null)
{
query = query.Where(row => row.UserId == criteria.UserId);
}
if (criteria.CreatedBy != null)
{
query = query.Where(row => row.CreatedBy == criteria.CreatedBy);
}
if (criteria.CreatedDate != null
&& criteria.CreatedDate.DateFrom.Date != DateTime.MinValue.Date)
{
query = query.Where(row => row.CreatedDate >= criteria.CreatedDate.DateFrom);
}
if (criteria.CreatedDate != null
&& criteria.CreatedDate.DateTo.Date != DateTime.MaxValue.Date)
{
query = query.Where(row => row.CreatedDate <= criteria.CreatedDate.DateTo);
}
if (criteria.ModifiedBy != null)
{
query = query.Where(row => row.ModifiedBy == criteria.ModifiedBy);
}
if (criteria.ModifiedDate != null
&& criteria.ModifiedDate.DateFrom.Date != DateTime.MinValue.Date)
{
query = query.Where(row => row.ModifiedDate >= criteria.ModifiedDate.DateFrom);
}
if (criteria.ModifiedDate != null
&& criteria.ModifiedDate.DateTo.Date != DateTime.MaxValue.Date)
{
query = query.Where(row => row.ModifiedDate <= criteria.ModifiedDate.DateTo);
}
if (criteria.SortBy != null)
{
query = query.OrderBy(string.Format(
"{0} {1}",
criteria.SortBy,
criteria.SortOrder == ListSortDirection.Ascending ? "ASC" : "DESC"));
}
if (criteria.SkipRecords != null)
{
query = query.Skip(criteria.SkipRecords.Value);
}
if (criteria.MaximumRecords != null)
{
query = query.Take(criteria.MaximumRecords.Value);
}
return query;
}