如何知道,如果一个领域是数字在LINQ to SQL [英] How to know if a field is numeric in Linq To SQL
问题描述
我需要选择一个表行,其中一列的值是数字,任何帮助
I need to select the rows of a table where a column value is numeric, any Help?
编辑:我有varchar列,我需要选择。那些是数字和不属于那些
I have a varchar column and I need to select the ones that are numbers and the ones that are not.
编辑2:Integer.TryParse不能使用,因为它不能被转换到SQL
EDIT 2: Integer.TryParse cannot be use because it cannot be translate to SQL.
推荐答案
我不知道是否有用于int.TryParse()在LinqToSQL映射,但你很可能通过执行查询做它在两个步骤,铸造到一个列表,然后选择与LinqToObjects名单出来
I don't know if there is a mapping for int.TryParse() in LinqToSQL, but you could probably do it in two steps by performing the query, casting to a List, then selecting out of the list with LinqToObjects.
int i;
var query = context.Table.ToList();
var intQuery = query.Where( t => int.TryParse( t.Column, out i ) );
您可能想要看的动态LINQ 了。这将允许你这样做是这样的:
You might want to look at Dynamic LINQ, too. That would allow you to do something like:
var query = context.Table.Where( "IsNumeric(Column)" );
修改动态LINQ是VS2008的代码示例用,挂在斯科特Guthrie的博客,我已经上面链接。
EDIT Dynamic LINQ is available in the VS2008 Code Samples, linked to from Scott Guthrie's blog, which I've linked above.
这篇关于如何知道,如果一个领域是数字在LINQ to SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!