I want to use a Linq query to calculate the length of strings and return only those which are greater than 7 characters long. The following code works well for "strings":
public IEnumerable<string> LengthOfNames()
{
this._context.ContextOptions.LazyLoadingEnabled = false;
var Query = from c in this._context.CustomerInfoes
where c.CustomerName.Length > 7
orderby c.CustomerName.Length
select c.CustomerName;
return Query.ToList();
}
But, when I use a similar query for "Integers", I get an error " 'int' does not contain a definition for 'Length' and no extension method 'Length' accepting a first argument etc etc.." Here's the code:
public IEnumerable<int> LengthOfNumbers()
{
this._context.ContextOptions.LazyLoadingEnabled = false;
var Query = from c in this._context.CustomerInfoes
where c.ContactNo.Length > 7
orderby c.ContactNo.Length
select c.ContactNo;
return Query.ToList();
}
As an alternative, I tried this:
public IEnumerable<int> GreaterThanSeven()
{
this._context.ContextOptions.LazyLoadingEnabled = false;
var Query = from c in this._context.CustomerInfoes
where c.ContactNo > 9999999
orderby c.ContactNo
select c.ContactNo;
return Query.ToList();
}
Which works just fine. My question is : Is this the correct (or the only) way to calculate the length of a numeric string?