使用F#查询实体框架的示例

时间:2022-12-19 09:51:38

I'm looking all over Google to find an example or tutorial about using F# to query an Entity data source.

我正在寻找一个关于使用F#查询实体数据源的示例或教程。

Honestly I haven't found much. Have any of you had any luck ?

老实说,我没有找到太多。你们有没有运气好吗?

1 个解决方案

#1


The following is an example I was able to pieces together from what i found on this blog

以下是我能够根据我在此博客上找到的内容拼凑而成的示例

open Microsoft.FSharp.Linq.QuotationEvaluation
open Microsoft.FSharp.Linq

let IsPermited (serviceName:string) =
  //Instantiate the Entity 
  let data = new BusModelContainer()

  //Build your query
  let services = Query.query <@ seq{ for service in data.ServiceSet do
                         service.Name.Equals(serviceName) && service.IsEnabled then
                               yield service } @>
  if Seq.is_empty services then 
    false
  else
    true

Here is the code from the blog that showed me how to go about selecting from an Entity

以下是博客中的代码,向我展示了如何从实体中进行选择

  let db = new FSharpSampleDB(connString)  

  Query.query <@ seq { for c in db.Customers do  
                       if id = c.CustomerId then  
                          yield (new Customer(c.CustomerId, c.Name, c.Balance))}   
              |> Seq.hd @> :> ICustomer  

#1


The following is an example I was able to pieces together from what i found on this blog

以下是我能够根据我在此博客上找到的内容拼凑而成的示例

open Microsoft.FSharp.Linq.QuotationEvaluation
open Microsoft.FSharp.Linq

let IsPermited (serviceName:string) =
  //Instantiate the Entity 
  let data = new BusModelContainer()

  //Build your query
  let services = Query.query <@ seq{ for service in data.ServiceSet do
                         service.Name.Equals(serviceName) && service.IsEnabled then
                               yield service } @>
  if Seq.is_empty services then 
    false
  else
    true

Here is the code from the blog that showed me how to go about selecting from an Entity

以下是博客中的代码,向我展示了如何从实体中进行选择

  let db = new FSharpSampleDB(connString)  

  Query.query <@ seq { for c in db.Customers do  
                       if id = c.CustomerId then  
                          yield (new Customer(c.CustomerId, c.Name, c.Balance))}   
              |> Seq.hd @> :> ICustomer