简体   繁体   English

为什么FSharp.Data.SqlClient记录作为对象公开?

[英]Why is FSharp.Data.SqlClient record exposed as object?

I'm working on a demo where I can show how easy it is to use the SqlClient type provider in a F# library and then consume it from C#, I think this might be one way to get things into projects. 我正在进行一个演示,我可以展示在F#库中使用SqlClient类型提供程序然后从C#中使用它是多么容易,我认为这可能是将事情纳入项目的一种方法。 Since many people using C# want to use interfaces etc. I thought I show them that it is possible to combine everything, but I don't get the expected result. 由于许多使用C#的人想要使用接口等。我想我告诉他们可以将所有内容组合在一起,但是我没有得到预期的结果。 I have the following F# code which works as expected in F#: 我有以下F#代码在F#中按预期工作:

module Orders = 
    [<Literal>]
    let connStr = """XXXXXXXXXXXX"""
    type OrdersPerEmployee = SqlCommandProvider<"OrdersPerEmployee.sql", connStr>

open Orders
type IOrdersRepo =
    abstract member getOrdersPerEmployee : int -> OrdersPerEmployee.Record seq
type OrdersRepo() =
    interface IOrdersRepo with
        member this.getOrdersPerEmployee(employeeId) = 
            let query = new OrdersPerEmployee()
            query.Execute(employeeId)

But when I try to use it from my C# app I don't get that the getOrdersPerEmployee returns an enumerable of records, instead it returns an enumerable of objects: 但是当我尝试从我的C#应用​​程序中使用它时,我没有得到getOrdersPerEmployee返回可枚举的记录,而是返回一个可枚举的对象:

IOrdersRepo repo = new OrdersRepo();
var data = repo.getOrdersPerEmployee(4).ToList();
data.ForEach(y => Console.WriteLine(y));
Console.ReadLine();

In the code above I expceted to get intellisense on y in the lambda, but nothing. 在上面的代码中,我发现在lambda中的y上获得intellisense,但没有。 Any ideas? 有任何想法吗?

Because SqlCommandProvider is erasing types kind. 因为SqlCommandProvider是类型的擦除类型。 It means types it generates can be consumed only from F#. 这意味着它生成的类型只能从F#中使用。 Contrary, SqlEnumProvider from the same FSharp.Data.SqlClient library is generated types kind and can be consumed by C# (via proxy project). 相反,来自相同FSharp.Data.SqlClient库的SqlEnumProvider是生成类型类型并且可以由C#(通过代理项目)使用。 It works especially nice when CLIEnum=true. 当CLIEnum = true时,它工作得特别好。 For a deeper discussion on erased vs generated types see How do I create an F# Type Provider that can be used from C#? 有关已擦除和生成类型的更深入讨论,请参阅如何创建可从C#使用的F#类型提供程序?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM