亚音速查询,以确定是否值以数字 [英] Subsonic query to determine if value starts with numeric

查看:155
本文介绍了亚音速查询,以确定是否值以数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个后续的<一个href="http://stackoverflow.com/questions/5702168/linq-to-sql-query-to-determine-if-value-starts-with-numeric">this问题,但是上下文已经改变。打破接受的解决方案。

This is a follow-up of this question, however the context has changed. Breaking the accepted solution.

这个时候,我试图使用亚音速,但它使用previous接受的解决方案会引发errormessage的

System.NotSupportedException: The method 'get_Chars' is not supported
...
Line 36:             char[] nums = "0123456789".ToCharArray();
Line 37: 
Line 38:             var b = repository.GetAll().Where(q => nums.Contains(q.BrukerIdent[0])).ToList();
Line 39: 
Line 40: 

据我可以告诉 q.BrukerIdent 是一个字符串。所以我有点甩...

As far as I can tell q.BrukerIdent is a string. So I'm a bit thrown...

推荐答案

忘记LINQ - 不要使用它。有一种更好的方式来实现自己的目标。使用SQL。你会如果你刚刚使用已完成 SQL - 它只是一个的基本模式搜索

Forget LINQ - Don't use it. There is a better way to accomplish your goal. Use SQL. You'd be done already if you would've just used SQL - it's just a basic pattern search.

亚音速?使用 CodingHorror 并使用相应的SQL。

Subsonic? Use a CodingHorror and use the appropriate SQL.

CodingHorror 是一类就是在亚音速组装。它给你一个方法来执行具体的,手写的SQL的情况下的试图达到同样的效果与LINQ将是困难的,如果不是不可能的,以及时间,因此完全是浪费

CodingHorror is a class that is in the SubSonic assembly. It gives you a way to execute specific, hand-written SQL for instances where trying to achieve the same result with LINQ would be difficult if not impossible, and therefore a complete waste of time.

您也可以执行 CodingHorror 查询,并要求它给你结果你的强类型对象的列表。

You can also execute a CodingHorror query and ask it to give you the results as a list of your strongly-typed objects.

下面是一个使用CodingHorror的,应该解决您的问题,但你必须填写一对夫妇的资料(表名,类型名称)。

Here's a use of CodingHorror that should solve your problem, but you'll have to fill in a couple of the particulars (table name, type name).

var query = new CodingHorror(@"SELECT * FROM YourTableHere 
                               WHERE BrukerIdent LIKE '[a-z0-9]%'");
var matchingItems = query.ExecuteTypedList<YourTypeHere>();

此外,还有的是一个有点出走使用亚音速,甚至更大的ORM的一般。我建议在看 PetaPoco (或块状,或小巧玲珑,等)。 PetaPoco的作者是由他不得不用经验推动 CodingHorror 过于频繁的灵活运用亚音速项目。

Also, there's been a bit of an exodus from using SubSonic, and even larger ORM's in general. I recommend looking at PetaPoco (or Massive or Dapper, etc.). The author of PetaPoco was driven by his experience of having to use CodingHorror far too often in projects that utilized SubSonic.

这篇关于亚音速查询,以确定是否值以数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆