亚音速查询,以确定是否值以数字亚音速、数字

由网友(智者永不坠入爱河)分享简介:这是一个后续的this问题,但是上下文已经改变。打破接受的解决方案。的This is a follow-up of this question, however the context has changed. Breaking the accepted solution.这个时候,我试图使用亚音速,但它使用pre...

这是一个后续的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.

阅读全文

相关推荐

最新文章