Reputation: 4292
I am using a TypeProvider to access some data like this:
type internal SqlConnection =
SqlEntityConnection<ConnectionString =
@"XXXXXXXXXX">
type FooRepository () =
member x.GetFoo (Id) =
let context = SqlConnection.GetDataContext()
query {for foo in context.Foos do
where (foo.Id = Id)
select foo}
The problem is I am getting this:
The type 'FooRepository' is less accessible than the value, member or type 'member System.Linq.IQueryable' it is used in
I see the same problem asked on SO here.
Since I want to expose this type and I don't like the solutions on SO, I tried doing this:
SqlDataConnection<ConnectionString =
@"XXXXXXX">
The problem is that the database is on Azure Sql Server so I am getting this:
The type provider 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: Error reading schema. Warning : SQM1012: Unable to extract table 'dbo.Foos from SqlServer.
Does anyone have an idea about how to get around this? One of the best things about using TPs is that I don't need to explicitly defines the types - but it looks like I am going to have to? Ugh
Upvotes: 3
Views: 1493
Reputation: 243051
Are you sure the error you are getting is the one you posted here? My impression is that
the type which is less accessible should be the one from the generated database schema
(because you mark that as internal
).
I tried reproducing your error by writing a simple library that uses the Northwind database:
open Microsoft.FSharp.Data.TypeProviders
type internal Nwind = SqlDataConnection<"Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True">
type NwindLibrary() =
let nw = Nwind.GetDataContext()
member this.Products = nw.Products
And I get the following message:
The type 'Products' is less accessible than the value, member or type 'member Class1.Products : System.Data.Linq.Table' it is used in C:\temp\Library1\Library1\Library1.fs 9 17 Library1
This is what I was expecting - because the Nwind
type (generated by a provider) is marked as internal
. However, the NwindLibrary
type is public and the property Products
(that I defined) returns a value of type IQueryable<Table<Nwind.ServiceTypes.Product>>
. The compiler error is not particularly useful here (because it says that the type returns just Table
), but the problem is that Nwind.ServiceTypes.Product
is internal and so you cannot return it in a public property of a public type.
If you make the Nwind
type public, then it should work fine. If you do not want to make the generated types public, then you'll have to wrap the returned values in your custom types. For example, even if you leave the type internal, the following works fine (returning a tuple instead of generated type):
member this.Products =
query { for p in mys.Products do
select (p.ProductID, p.ProductName) }
Upvotes: 3