本文整理匯總了C#中Service.List.AsQueryable方法的典型用法代碼示例。如果您正苦於以下問題:C# List.AsQueryable方法的具體用法?C# List.AsQueryable怎麽用?C# List.AsQueryable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Service.List
的用法示例。
在下文中一共展示了List.AsQueryable方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateFlyRepository
private static IFlyRepository CreateFlyRepository()
{
var flyRepo = new Mock<IFlyRepository>();
var flys = new List<Fly>
{
new Fly{Id = 1, Description = "First Fly", DateOfFly = DateTime.Now, Owner = new FlyOwner{Id = 1, Name = "Paulo" } },
new Fly{Id = 2, Description = "Second Fly", DateOfFly = DateTime.Now, Owner = new FlyOwner{Id = 1, Name = "Paulo" } },
new Fly{Id = 3, Description = "Third Fly", DateOfFly = DateTime.Now, Owner = new FlyOwner{Id = 1, Name = "Paulo" } }
};
flyRepo.Setup(s => s.GetAll()).Returns(flys.AsQueryable());
return flyRepo.Object;
}
示例2: GetRolePermissionsQuery
private List<RolePermissionModel> GetRolePermissionsQuery(Guid id, [FromUri] JqGridSearchModel searchModel, out int totalNumber, int maxRecords = Constants.DEFAULT_MAX_RECORDS_RETURN)
{
if (id == default(Guid))
throw new ArgumentNullException("Role id cannot be empty.");
int startRow = (searchModel.page * searchModel.rows) + 1;
int skip = (searchModel.page > 0 ? searchModel.page - 1 : 0) * searchModel.rows;
Role role = _roleService.GetById(id);
List<Permission> allPermission = _permissionService.GetAllPermissions();
List<RolePermissionModel> rolePermissions = new List<RolePermissionModel>();
foreach (var permission in allPermission)
{
bool hasPermission = role.Permissions.AsQueryable().Any(x => x.Id == permission.Id);
rolePermissions.Add(new RolePermissionModel { Id = permission.Id, Name = permission.Name, Description = permission.Description, HasPermission = hasPermission });
}
//note - these queries require "using System.Dynamic.Linq" library
IQueryable<RolePermissionModel> query = rolePermissions.AsQueryable();
var data = Web.Infrastructure.Util.GetGridData<RolePermissionModel>(searchModel, query);
totalNumber=data.TotalNumber;
return data.Items.ToList();
}
示例3: GetUserRolesQuery
private Web.Infrastructure.GridModel<UserRoleModel> GetUserRolesQuery(Guid id, [FromUri] JqGridSearchModel searchModel)
{
if (id == default(Guid))
throw new ArgumentNullException("User id cannot be empty.");
int startRow = (searchModel.page * searchModel.rows) + 1;
int skip = (searchModel.page > 0 ? searchModel.page - 1 : 0) * searchModel.rows;
//if (!HasPermission(id, Constants.ROLE_ADMIN))
// throw new Exception("Unauthorized");
NhUserAccount user = _userService.GetById(id);
List<Role> allRoles = _roleService.GetAllRoles();
if (!User.IsInRole(Constants.ROLE_ADMIN))
allRoles = allRoles.Where(x => x.Name != Constants.ROLE_ADMIN).ToList();
List<UserRoleModel> userRoles = new List<UserRoleModel>();
foreach (Role role in allRoles)
{
bool hasRole = user.Roles.AsQueryable().Any(x => x.Id == role.Id);
//userRoleEditModel.Roles.Add(new UserRoleModel { UserId=id, Role = role, HasRole = hasRole });
userRoles.Add(new UserRoleModel { Id = role.Id, Name = role.Name, Description = role.Description, HasRole = hasRole });
}
var query = userRoles.AsQueryable();
var data = Web.Infrastructure.Util.GetGridData<UserRoleModel>(searchModel, query);
return data;
}