0

重複の可能性:
エンティティへの linq がメソッドを認識しない

文字列が数字で始まるかどうかを確認しようとしています

var product09 = DataContext.Products.Where(x => Char.IsNumber(x.ProductName,0));

私も試しました

var product09 = DataContext.Products.Where(x => Char.IsNumber(x.ProductName[0]));

次のエラーが表示されます。

Boolean IsNumber(Char)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NotSupportedException: Boolean IsNumber(Char)

助けていただけますか?

4

2 に答える 2

2

コメントに基づいて、NHibernate を使用しています。CreateCriteriaメソッドを使用できるはずです:

using (ISession session = sessionFactory.OpenSession())
{
    var result = session.CreateCriteria<Product>()
                        .Add(Restrictions.Like("ProductName", "[0-9]%"))
                        .List<Product>();
}

使用することもできます.Add(Restrictions.Like("ProductName", "[0-9]", MatchMode.Start))

別のオプションは、HQL を使用することです。

var query = "from Product p where p.ProductName like '[0-9]%'";
var result = session.CreateQuery(query).List<Product>();

このSqlMethods.Likeメソッドは LINQ to SQL で使用できます。

var query = dc.Products.Where(x => SqlMethods.Like(x.ProductName, "[0-9]%"));
于 2012-04-30T22:31:23.033 に答える
1

'どうですか:

char[] numbers = new[] { '0', '1', '2' , '3', '4', '5', '6', '7', '8', '9' };
DataContext.Products.Where(x => numbers.Contains(x.Substring(0, 1));
于 2012-04-30T22:29:22.400 に答える