这是我从数据库中检索非活动/活动用户列表的查询。我的问题是,我的查询似乎太复杂了。所以你能给我一个提示如何增强我的查询。
这是我的代码
using (basecampcoreEntities dbs = ConfigAndResource.BaseCampContext())
{
//loads all user where isactive property has the same value as IsActive
var Users = from useritem in dbs.users
where useritem.useraccount.IsActive.Equals(IsActive)
orderby useritem.useraccount.CreatedDate
select useritem;
//check if users count is greater than 0
if (Users.Count() > 0)
{
List<user> CasebookUser = new List<user>();
switch (SearchBy)
{
case DTO::SearchBy.FirstName:
{
CasebookUser = Users.Where(item => item.FirstName.ToUpper().Equals(SearchText.ToUpper())).Skip(skip).Take(take).ToList();
} break;
case DTO::SearchBy.LastName:
{
CasebookUser = Users.Where(item => item.LastName.ToUpper().Equals(SearchText.ToUpper())).Skip(skip).Take(take).ToList();
} break;
case DTO::SearchBy.LoginID:
{
CasebookUser = Users.Where(item => item.LoginID.ToUpper().Equals(SearchText.ToUpper())).Skip(skip).Take(take).ToList();
} break;
case DTO::SearchBy.None:
CasebookUser = Users.Skip(skip).Take(take).ToList();
{
} break;
}
//transform the data into DTO class
return (from item in CasebookUser
select new DTO::User
{
LoginID = item.LoginID,
FirstName = item.FirstName,
LastName = item.LastName,
MiddleName = item.MiddleName,
Birhtday = item.userinfo != null ? item.userinfo.Birthday : DateTime.UtcNow
}).ToList();
}
return null;