如何检查 "params Expression" 是否不包含值
how to check if "params Expression" does not contain values
我有以下存储库方法:-
public async Task<Skill> FindSkill(int id, params Expression<Func<Skill, object>>[] includeProperties)
{
var query = context.Skills.AsQueryable();
if (includeProperties != null )
query = includeProperties.Aggregate(query, (current, include) => current.Include(include));
return await query.SingleOrDefaultAsync(a => a.SkillID == id);
}
我这样调用这个方法:-
public async Task<ActionResult> Deactivate(int id, Byte[] timestamp = null)
{
var skill = await unitofwork.SkillRepository.FindSkill(id);
//snip
}
但我无法检测到我什么时候没有通过 params Expression
,我也尝试了以下检查但没有成功:-
includeProperties.Count() != 0 || includeProperties[0].Name == "0"
现在我注意到在 VS 中传递空列表时将收到以下内容:-
使用 params 且未为其提供任何参数时。将创建一个空数组。你应该使用 includeProperties.Length !=0 正如 Nick Bailey 在他的评论中所建议的那样。
我有以下存储库方法:-
public async Task<Skill> FindSkill(int id, params Expression<Func<Skill, object>>[] includeProperties)
{
var query = context.Skills.AsQueryable();
if (includeProperties != null )
query = includeProperties.Aggregate(query, (current, include) => current.Include(include));
return await query.SingleOrDefaultAsync(a => a.SkillID == id);
}
我这样调用这个方法:-
public async Task<ActionResult> Deactivate(int id, Byte[] timestamp = null)
{
var skill = await unitofwork.SkillRepository.FindSkill(id);
//snip
}
但我无法检测到我什么时候没有通过 params Expression
,我也尝试了以下检查但没有成功:-
includeProperties.Count() != 0 || includeProperties[0].Name == "0"
现在我注意到在 VS 中传递空列表时将收到以下内容:-
使用 params 且未为其提供任何参数时。将创建一个空数组。你应该使用 includeProperties.Length !=0 正如 Nick Bailey 在他的评论中所建议的那样。