简体   繁体   English

.NET:从解析数据库中检索数据

[英].NET: Retrieving Data From parse database

I have installed the Parse reference into my MVC Application by downloading it through Package Manager. 我已经通过Package Manager下载了Parse引用,并将其安装到了我的MVC应用程序中。 The reference that has been added is Parse 1.5.5. 已添加的引用是解析1.5.5。

ParseClient.Initialize("app_key", ".net_key");
var test = new ParseObject("test");           
test["username"] = "test";
test["password"] = "test";
test.SaveAsync();

ParseQuery<ParseObject> query = ParseObject.GetQuery("test");
ParseObject test1 = query.GetAsync("mVzhilmRJw");

The issue here is that GetAsync method returns ParseQuery type as opposed to ParseObject Type as mentioned in the documentation. 这里的问题是GetAsync方法返回的ParseQuery类型与文档中提到的ParseObject类型相反。 Further, the metadata shows that the method GetAsync is not of Async type, which I presumably feel is the root cause. 此外,元数据显示方法GetAsync不是Async类型,我想这可能是根本原因。

The following is the error that I'm getting when I try to execute the LINQ version of the above method: 以下是我尝试执行上述方法的LINQ版本时遇到的错误:

var query1 = ParseObject.GetQuery("test")
    .WhereEqualTo("objectId", "W70H7Ad8rv");
IEnumerable<ParseObject> results = 
    (IEnumerable<Parse.ParseObject>)query1.FindAsync(); 

Error: 错误:

Unable to cast object of type 'System.Threading.Tasks.UnwrapPromise 1[System.Collections.Generic.IEnumerable1[Parse.ParseObject]]' to type 'System.Collections.Generic.IEnumerable 1[Parse.ParseObject]'. 无法将类型为“ System.Threading.Tasks.UnwrapPromise 1[System.Collections.Generic.IEnumerable1[Parse.ParseObject]]' to type 'System.Collections.Generic.IEnumerable对象1[System.Collections.Generic.IEnumerable1[Parse.ParseObject]]' to type 'System.Collections.Generic.IEnumerable 1 [Parse.ParseObject]”类型。

I'm trying out Parse as the backend for the first time and not sure if I have included the appropriate references. 我第一次尝试将Parse作为后端,并且不确定是否包含适当的引用。 Further I'm using .NET 4.5 framework, Visual Studio 2012 on a Windows 7 OS. 此外,我正在Windows 7 OS上使用.NET 4.5框架,Visual Studio 2012。 Does this have anything to do with the issue I am facing. 这与我面临的问题有关系吗?

Any help is highly appreciated. 非常感谢您的帮助。

TLDR: How do we retrieve data from Parse in a .NET Web application using .NET 4.5 framework, VS 2012 and what are the references corresponding to Parse that have to be added. TLDR:我们如何使用.NET 4.5框架,VS 2012在.NET Web应用程序中从Parse检索数据,以及必须添加哪些与Parse对应的引用。

The solution for this issue turned out to be pretty straight forward. 事实证明,解决该问题的方法非常简单。 It is required that we know what async is all about. 要求我们知道异步的全部含义。 This can be found here . 可以在这里找到。 It is important that an async method is called within an Async method only. 重要的是,只能在Async方法中调用async方法。 The sample of code can be as seen below 代码示例如下所示

public async void GetData()
{
    ParseClient.Initialize("app_key", ".net_key");
    var query1 = ParseObject.GetQuery("test").WhereEqualTo("objectId", "xxxxxxxx");
    var result = await query1.FindAsync();
}

If you want to know how not to block on call to an async method, you can refer here . 如果您想知道如何在调用异步方法时不阻塞,可以在这里参考。

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

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