-1
Model.GetData.Where(p => p.Value != null).ToList();

I have values in my database like below,

My Value Column:

Null
Null
5
16
ExampleValue1
ExampleValue2

p.value is string

I only want to see "ExampleValue1" and "ExampleValue2". How can i get datas not null and not numeric ?

Thilina H
  • 5,754
  • 6
  • 26
  • 56
user2902180
  • 1,021
  • 3
  • 12
  • 12

4 Answers4

7

Perhaps:

var BillingNumbers = Model.GetData
    .Where(p => p.Value != null && SqlFunctions.IsNumeric(p.Value) == 0);
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
0

Assuming the results are of different types, you can query by type like this: var results = from item in collection where (item is String) select item;

Example program:

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);
}
Micah Zoltu
  • 6,764
  • 5
  • 44
  • 72
  • I maybe nitpicking here, but the requirement was not numeric and not null, not `item is String`. It could well be an IEnumerable or bool for what its worth – Marco Oct 21 '13 at 07:57
  • 1
    `Linq-To-Objects` and `Linq-To-Entities` are very different. You can always add `AsEnumerable` but that would read the whole result set from DB before applying the where condition. – Tim Schmelter Oct 21 '13 at 07:59
0

You can rely to this code : result is just contains string

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);
                }
            }
        });
Hamid Bahmanabady
  • 665
  • 1
  • 8
  • 20
-1

Try on this..

int i;
var resultList = Model.GetData.Where(p => p.Value != null).ToList();
var finalResult= resultList.Where( t => !int.TryParse( t.Value , out i));
Thilina H
  • 5,754
  • 6
  • 26
  • 56