[英]How can I check if the integer value of a string is less than something in LINQ?
I have the following: 我有以下几点:
var topRole = 25;
var menuItems = _contentRepository.GetPk()
.Where(m => m.Status <= topRole)
.OrderBy(m => m.Order)
.Select(m => new MenuItem
Status has values of "00", "05" or "10" 状态的值为“ 00”,“ 05”或“ 10”
Is there some way I can convert m.Status to an integer and then compare to see if it is less than or equal to topRole? 有什么方法可以将m.Status转换为整数,然后进行比较以查看它是否小于或等于topRole?
use int.Parse(m.Status)
使用int.Parse(m.Status)
var menuItems = _contentRepository.GetPk()
.Where(m => int.Parse(m.Status) <= topRole)
.OrderBy(m => m.Order)
.Select(m => new MenuItem)
EDIT: changed "parse" to "Parse". 编辑:更改为“解析”的“解析”。
var menuItems = _contentRepository.GetPk()
.Where(m => int.Parse(m.Status) <= topRole)
.OrderBy(m => m.Order)
.Select(m => new MenuItem);
If this query is for LINQ to SQL, you may need to use Convert.ToInt32
instead: 如果此查询用于LINQ to SQL,则可能需要改用Convert.ToInt32
:
var menuItems = _contentRepository.GetPk()
.Where(m => Convert.ToInt32(m.Status) <= topRole)
.OrderBy(m => m.Order)
.Select(m => new MenuItem);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.