Model.GetData.Where(p => p.Value != null).ToList();
我的数据库中有如下值,
我的价值专栏:
Null
Null
5
16
ExampleValue1
ExampleValue2
p.value 是字符串
我只想看到“ExampleValue1”和“ExampleValue2”。如何获取不为空且不为数字的数据?
Model.GetData.Where(p => p.Value != null).ToList();
我的数据库中有如下值,
我的价值专栏:
Null
Null
5
16
ExampleValue1
ExampleValue2
p.value 是字符串
我只想看到“ExampleValue1”和“ExampleValue2”。如何获取不为空且不为数字的数据?
也许:
var BillingNumbers = Model.GetData
.Where(p => p.Value != null && SqlFunctions.IsNumeric(p.Value) == 0);
假设结果是不同的类型,你可以像这样按类型查询:
var results = from item in collection where (item is String) select item;
示例程序:
static void Main(string[] args)
{
var collection = new List<Object>
{
5,
1.5,
null,
"foo",
"bar",
};
var results = from item in collection where (item is String) select item;
foreach (var result in results)
{
Console.WriteLine(result);
}
System.Threading.Thread.Sleep(10000);
}
您可以依赖此代码:结果仅包含字符串
List<object> result = new List<object>();
var MyList = new List<Object>{
523,
2.555,
null,
"ExampleValue1",
"ExampleValue2",
};
MyList.ForEach(x =>
{
if (x != null)
{
if (!string.IsNullOrEmpty(Regex.Replace(x.ToString(), @"^[0-9]*(?:\.[0-9]*)?$", string.Empty)))
{
result.Add(x);
}
}
});
试试这个。。
int i;
var resultList = Model.GetData.Where(p => p.Value != null).ToList();
var finalResult= resultList.Where( t => !int.TryParse( t.Value , out i));