c# - Unity 使用 AppServices 连接到 azure Sql 数据库

标签 c# azure unity-game-engine

所以我想在统一项目中使用连接到我的Azure Sql数据库, 我使用了 app services Github project 的自述文件中提供的代码:

    public class AzureConnect : MonoBehaviour {
    private MobileServiceClient _client;
    private MobileServiceTable<Score> _table;
    // Use this for initialization
    void Start () {
        _client = new MobileServiceClient("https://myService.azurewebsites.net"); // <- add your app url here.
        _table = _client.GetTable<Score>("Score");
        ReadItems();
    }
    private void ReadItems()
    {
        StartCoroutine(_table.Read<Score>(OnReadItemsCompleted));
    }

    private void OnReadItemsCompleted(IRestResponse<Score[]> response)
    {
        if (!response.IsError)
        {
            Debug.Log("OnReadCompleted: " + response.Url + " data: " + response.Content);//content shows the content of the table properly
            Score[] items = response.Data;//Data is always null
            Debug.Log("Todo items count: " + items.Length);
        }
        else
        {
            Debug.LogWarning("Read Error Status:" + response.StatusCode + " Url: " + response.Url);
        }
    }
}

代码工作完美,并且可以很好地连接到我的数据库,但由于某种原因,尽管响应内容返回一个包含分数表中数据的字符串,但响应数据始终为空,知道可能是什么问题吗?

PS:应用程序服务的 URL 不是我仅用于演示目的的真实 URL。

最佳答案

好吧,我已经为此苦苦挣扎了几个小时,在发布问题 6 分钟后,我找到了答案,所以这里是答案,以便任何面临此问题的人都可以知道原因:

问题是,当我以这种方式声明它时,我并没有将我的分数类声明为[Serialized],它完美地工作了。

关于c# - Unity 使用 AppServices 连接到 azure Sql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43415155/

相关文章:

c# - MVC中如何删除多个列表项?

c# - Where 子句后跟 FirstOrDefault 返回相同的值

c# - 如何获取Azure存储帐户 key

Azure Function 工作线程与实例

android - Profiler 中的内存使用量比实际设备少得多

iphone - 将 IOS native 对象传回 unity3d

C# linq 查询聚合可为空 boolean 值

c# - LINQPad 如何引用其他类,例如LINQ in Action 示例中的书籍

azure - 在一个 DocumentDb 集合中存储不同的文档类型

unity-game-engine - 编写一个简单的光线转换着色器