2014-01-27 1 views
3

액세스하는 방법 :F #의 SQL 형 제공자 :이 같은 일부 데이터에 액세스 할 TypeProvider을 사용하고

문제는 내가 이것을 얻고있다

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 type 'FooRepository' is less accessible than the value, member or type 'member System.Linq.IQueryable' it is used in

내가 같은 문제를 참조 SO here에 물었다.

나는이 유형을 보여주고 싶지 내가 SO에 대한 솔루션을 좋아하지 않기 때문에, 나는이 일을 시도 :

SqlDataConnection<ConnectionString = 
    @"XXXXXXX"> 

문제하면 데이터베이스가 푸른는 SQL 서버 그래서 나는이 점점 오전에 있다는 것이다 :

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.

아무도이 문제를 해결하는 방법에 대한 아이디어가 있습니까? TP 사용에 관한 가장 좋은 점 중 하나는 유형을 명시 적으로 정의 할 필요가 없다는 것입니다.하지만 꼭해야 할 것처럼 보입니다. Ugh

답변

3

여기에 게시 한 오류가 발생 했습니까? 제 생각에 덜 접근 할 수있는 유형은 생성 된 데이터베이스 스키마 에서 가져온 것이어야합니다 (그 이유는 이것을 internal으로 표시했기 때문입니다).

나는 Northwind 데이터베이스 사용하는 간단한 라이브러리를 작성하여 오류를 재현하려 :

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 

을 그리고 다음과 같은 메시지가 얻을 :

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

이 내가 기다리고 있었다 무엇을 - 때문에 Nwind 유형 (제공자가 생성 함)은 internal으로 표시됩니다. 그러나 NwindLibrary 유형은 public이며 Products (정의한 속성)은 IQueryable<Table<Nwind.ServiceTypes.Product>> 유형의 값을 반환합니다. 컴파일러 오류는 여기에서 특히 유용하지 않습니다 (형식에서 단지 Table을 반환한다고하기 때문에). Nwind.ServiceTypes.Product은 내부 형식이므로 public 형식의 public 속성에서 반환 할 수 없습니다.

Nwind 유형을 공개로 설정하면 정상적으로 작동합니다. 생성 된 유형을 공개하지 않으려면 사용자 정의 유형에 리턴 값을 랩핑해야합니다. 예를 들어, 내부 형식을 남겨 두었더라도 다음은 올바르게 작동합니다 (생성 된 형식 대신 튜플을 반환 함).

member this.Products = 
    query { for p in mys.Products do 
      select (p.ProductID, p.ProductName) } 
+1

Azure에 대해 SqlDataConnection을 사용해 보셨나요? 나는 그것이 Azure Sql 서버 스토리지에 대해 사용될 수 있다고 생각하지 않습니다 ... –