亚音速查询以确定值是否以数字开头
这是 的后续内容这个问题,但是上下文已经改变了。打破了公认的解决方案。
这次我尝试使用 SubSonic,但它使用之前接受的解决方案抛出错误消息
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 是一个字符串。所以我有点迷茫了...
This is a follow-up of this question, however the context has changed. Breaking the accepted solution.
This time I'm trying to use SubSonic, but it throws an errormessage using the previous accepted solution
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:
As far as I can tell q.BrukerIdent
is a string. So I'm a bit thrown...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
忘记 LINQ - 不要使用它。有更好的方法来实现您的目标。使用 SQL。如果您只使用 SQL,那么您已经完成了 - 它只是一个 基本模式搜索。
亚音速?使用
CodingHorror
并使用适当的 SQL。CodingHorror
是 SubSonic 程序集中的一个类。它为您提供了一种执行特定的、手写 SQL 的方法,在这些情况下,尝试使用 LINQ 获得相同的结果即使不是不可能,也是很困难的,因此完全是浪费时间。您还可以执行
CodingHorror
查询并要求它以强类型对象列表的形式提供结果。这是 CodingHorror 的用法,应该可以解决您的问题,但您必须填写一些详细信息(表名称、类型名称)。
此外,人们已经开始放弃使用 SubSonic,甚至更大的 ORM。我建议查看 PetaPoco (或 Massive 或 Dapper 等)。 PetaPoco 的作者受到在使用 SubSonic 的项目中过于频繁地使用
CodingHorror
的经历的驱使。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.
Subsonic? Use a
CodingHorror
and use the appropriate SQL.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.You can also execute a
CodingHorror
query and ask it to give you the results as a list of your strongly-typed objects.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).
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.您是否尝试过使用
Substring
而不是字符索引器?请注意,我必须将
nums
设为 string[] 而不是 char[],因为 Substring() 返回字符串而不是 char。如果运行仍然存在问题,有时 SubSonic 喜欢将调用
.Contains()
的对象改为 IEnumerable,因此您可能必须这样做:Have you tried using
Substring
instead of the character indexer?Note I had to make
nums
a string[] instead of a char[] since Substring() returns a string not a char.Incase that still has a problem running, sometimes SubSonic likes for the object that
.Contains()
is being called on to be an IEnumerable instead, so you might have to do:您是否尝试在不使用 lambda 函数和其他东西的情况下完成它,以查看问题出在哪里?
Did you try to make it without using lambda functions and other stuff in order to see where the issue is ?
它需要将 linq 表达式转换为有效的 sql 表达式。
在我看来,您使用的 IQueryableProvider 不支持 getChars 方法(q.BrukerIdent 上的索引器)。
It needs to convert the linq expression to a valid sql expression.
It seems to me, the method getChars (the indexer on
q.BrukerIdent
) is not supported in the IQueryableProvider you use.