- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过 f# linq 不幸地创建一个“IN CLause” - 但似乎无法得到它。我尝试了两种选择:
作为序列表达式的一部分迭代天数列表:
let getHistoricalQuotes (securityId:int) (days:string seq) =
let results =
Query.query <@ seq {
for day in days do
for sq in db.SecurityQuote do
if sq.SecurityId =?! securityId && sq.Day = day then
yield sq ;
} @>
还有一个 List.exists 子句:
let getHistoricalQuotes (securityId:int) (days:string list) =
let results =
Query.query <@ seq {
for sq in db.SecurityQuote do
if sq.SecurityId =?! securityId && List.exists (fun d -> d = sq.Day) days then
yield sq ;
} @>
results
两者都给了我:
base {System.SystemException} = {"Method 'Microsoft.FSharp.Core.FSharpFunc
2[System.String,System.Boolean]
2[System.String,System.Boolean])' has no supported translation to SQL."}
ToFSharpFunc[String,Boolean](System.Converter
一如既往,提前感谢您的帮助...
<小时/>重写为:
let getHistoricalQuotes (securityId:int) (days:string list) =
let results =
Query.query <@
Query.join
db.SecurityQuote
days
(fun sq -> if(sq.SecurityId =?! securityId) then sq.Day else "")
(fun d -> d)
(fun sq d -> sq) @>
results
并得到这个异常:
System.Exception was unhandled
Message=The following construct was used in query but is not recognised by the F#-to-LINQ query translator: Value (["2010/01/04"; "2010/02/01"; "2010/03/01"; "2010/04/01"; "2010/05/03"; "2010/06/01"; "2010/07/01"; "2010/08/02"; "2010/09/01"; "2010/10/01"; "2010/11/01"; "2010/12/01"; "2010/01/29"; "2010/02/26"; "2010/03/31"; "2010/04/30"; "2010/05/31"; "2010/06/30"; "2010/07/30"; "2010/08/31"; "2010/09/30"; "2010/10/29"; "2010/11/30"; "2010/12/31"]) This is not a valid query expression. Check the specification of permitted queries and consider moving some of the query out of the quotation
删除引号不会导致错误 - 但它生成了一个极其错误的查询(selext * from Historicalquote)
<小时/>暂时作弊,直到我回来解决问题 - 但至少我可以保持签名相同,尽管我会破坏数据库。
let getHistoricalQuotes (securityId:int) (days:string list) =
let getQuote (day) =
Query.query <@ seq {
for sq in db.SecurityQuote do
if sq.SecurityId =?! securityId && sq.Day = day then
yield sq ;
} @> |> Seq.head
List.map (fun day -> getQuote day) days
<小时/>
根据下面的遗嘱,我尝试了这个
let getHistoricalQuotes (securityId:int) (days:string list) =
let results =
Query.query <@ seq {
for sq in db.SecurityQuote do
if sq.SecurityId =?! securityId && days.Contains(sq.Day) then
yield sq ;
} @>
results
但是无法编译
<小时/>Error 1 The field, constructor or member 'Contains' is not defined
最后 - (谢谢你):
let getHistoricalQuotes (securityId:int) (days:string array) =
let results =
Query.query <@ seq {
for sq in db.SecurityQuote do
if sq.SecurityId =?! securityId && days.Contains(sq.Day) then
yield sq ;
} @>
results
是的 - 您需要打开 System.Linq - 这些扩展方法是,或者至少部分 - 它们必须是,
最佳答案
它已经存在于 Linq 中,但与您习惯的相反:
days.Contains(day)
关于f# - FLinq SQL "IN Clause",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4109703/
我是一名优秀的程序员,十分优秀!