使用F#&;SQLite.Net.Async PCL创建数据库表

使用F#&;SQLite.Net.Async PCL创建数据库表,sqlite,f#,windows-8.1,portable-class-library,sqlite.net,Sqlite,F#,Windows 8.1,Portable Class Library,Sqlite.net,我试图在C#Windows8应用程序中使用F#项目创建一个表“Materials”。这可能在库(SQLite.Net.Async)中更为具体,但我没有太多的运气让它起作用。我明白了,erorr near“)”:语法错误,这是没有帮助的,如果我能看到它试图执行的完整SQL查询,我可能能够进一步解决这个问题 Sql.fsi namespace DataAccess open SQLite.Net.Async open SQLite.Net.Interop open System.Threading

我试图在C#Windows8应用程序中使用F#项目创建一个表“Materials”。这可能在库(SQLite.Net.Async)中更为具体,但我没有太多的运气让它起作用。我明白了,erorr near“)”:语法错误,这是没有帮助的,如果我能看到它试图执行的完整SQL查询,我可能能够进一步解决这个问题

Sql.fsi

namespace DataAccess

open SQLite.Net.Async
open SQLite.Net.Interop
open System.Threading.Tasks

module Sql =
    type Material =
        new : unit -> Material
        new : id:int * name:string -> Material
        member Id : int
        member Name : string
    val connect : ISQLitePlatform -> string -> SQLiteAsyncConnection
    val initTables : SQLiteAsyncConnection -> Task<SQLiteAsyncConnection.CreateTablesResult>
命名空间数据访问
打开SQLite.Net.Async
打开SQLite.Net.Interop
开放系统.Threading.Tasks
模块Sql=
val连接:ISQLitePlatform->string->SQLiteAsyncConnection
val initTables:SQLiteAsyncConnection->Task选项
Sql.fs

namespace DataAccess

open SQLite
open SQLite.Net
open SQLite.Net.Async
open SQLite.Net.Attributes
open System
open System.Threading.Tasks

module Sql =
    type Material (id : int, name : string) = 
        let mutable m_id : int = id
        let mutable m_name : string = name

        new() = Material(0, null)

        [<PrimaryKey>] [<AutoIncrement>]
        member this.Id
            with get() = m_id
            and set(value) = m_id <- value

        member this.Name
            with get() = m_name
            and set(value) = m_name <- value

        override this.ToString() = System.String.Format("[{0}] {1}", m_id, m_name)

    let connect (platform : SQLite.Net.Interop.ISQLitePlatform) (databasePath : string) : SQLiteAsyncConnection =
        let connectionString = SQLiteConnectionString(databasePath, false)
        let connectionFactory = new Func<SQLiteConnectionWithLock>(fun () -> new SQLiteConnectionWithLock(platform, connectionString));
        let connection = new SQLiteAsyncConnection(connectionFactory)
        connection

    let initTables (connection : SQLiteAsyncConnection) : Task<SQLiteAsyncConnection.CreateTablesResult> =
        connection.CreateTableAsync<Material>()
命名空间数据访问
开放式SQLite
打开SQLite.Net
打开SQLite.Net.Async
打开SQLite.Net.Attributes
开放系统
开放系统.Threading.Tasks
模块Sql=
[]
类型材质(id:int,名称:string)=
设可变m_id:int=id
让可变m_name:string=name
new()=材质(0,null)
[] [] []
成员:这个
使用get()=m_id
和设置(值)=m_id
没有一个
Hub.cs

async public void GetDB()
{
    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
    var file = await localFolder.CreateFileAsync("test.db", CreationCollisionOption.OpenIfExists);
    var filePath = file.Path;
    var connection = Sql.connect(new SQLitePlatformWinRT(), filePath);

    var result = await Sql.initTables(connection);
}
async private void StackPanel_轻敲(对象发送器,轻敲路由Deventargs e)
{
等待GetDB();
}
还有一个例外:

在mscorlib.dll中发生了“SQLite.Net.SQLiteException”类型的异常,但未在用户代码中处理
其他信息:near“)”:语法错误
“在SQLite.Net.Platform.WinRT.SQLiteApiWinRT.Prepare2(IDbHandle数据库,字符串查询)
在SQLite.Net.SQLiteCommand.Prepare()中
在SQLite.Net.SQLiteCommand.ExecuteNonQuery()中
在SQLite.Net.SQLiteConnection.Execute(字符串查询,对象[]args)
在SQLite.Net.SQLiteConnection.CreateTable中(键入ty,CreateFlags CreateFlags)
在SQLite.Net.Async.SQLiteAsyncConnection.c__DisplayClass0.b__1()中
在System.Threading.Tasks.Task`1.InnerInvoke()中
在System.Threading.Tasks.Task.Execute()中
---来自引发异常的上一个位置的堆栈结束跟踪---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中
在App1.HubPage1.d_u0.MoveNext()中
---来自引发异常的上一个位置的堆栈结束跟踪---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中
在App1.HubPage1.d_u9.MoveNext()中

我能够找出问题所在。是我的FSharp签名文件缺少“物料”定义

Sql.fsi

namespace DataAccess

open SQLite.Net.Async
open SQLite.Net.Interop
open System.Threading.Tasks

module Sql =
    type Material =
        new : unit -> Material
        new : id:int * name:string -> Material
        member Id : int
        member Name : string
    val connect : ISQLitePlatform -> string -> SQLiteAsyncConnection
    val initTables : SQLiteAsyncConnection -> Task<SQLiteAsyncConnection.CreateTablesResult>