c# - Select Max, but only on numeric values with LINQ to Entities -
I am trying to select the maximum sys_id
from a table where sys_id < / Code> column is a
varchar
type. Some lines are text, but I am only concerned with numerical values.
I have tried the following bit code, but they do not work - the LINQ does not seem to support the operation of the units. / P>
public string GetSysID () {(var reference = new DbEntities ()) {int i; // var intQuery = context.myTable.Where (t = & gt; int.TryParse (t.sys_id, outside i)). Maximum (); Int intQuery = Convert.ToInt32 (context.myTable.Where (P => IsNumber (p.sys_id). Max (P => p.sys_id)); // return reference.drawings.max (p = & gt; p.sys_id); Return intQuery.ToString (); }} Public Static Bull ID (string value) {int n; Return int.TryParse (value, out N); }
Is there any way to use LINQs to do entities?
use SqlFunctions.IsNumeric and Cast
iQueryableSource. Details about where (see X => SqlFunctions.IsNumeric (x.Number + ".0e0") == 1) // Down 0e0 Select (x = & gt; x.Number) .Cast & lt; Int & gt; () .max ()
UPDATE
You can search for a problem with a point or currency sign in a string , But still receiving ISNumeric == 1
. Because you want only integer, you should add .0e0
as the string
Comments
Post a Comment