Hi, all:
I am fairly new to Simple.Data. I am trying to use OWIN middleware with WebAPI , using Simple.Data as backend.
If I use it synchronously to get data from Simple.Data, it works fine, but if I use async/await pattern, it fails. Does Simple.Data not work with async/await? I searched the group, there was a similar question 3 years ago and Mark mentioned that would be worked in a month, so I thought it should have worked.
the error message is:
<InnerException>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Table 'dbo.GetAwaiter' not found, or insufficient permissions.
</ExceptionMessage>
<ExceptionType>Simple.Data.UnresolvableObjectException</ExceptionType>
<StackTrace>
at Simple.Data.Ado.Schema.TableCollection.Find(String tableName, String schemaName) at Simple.Data.Ado.Schema.TableCollection.Find(String tableName) at Simple.Data.Ado.Schema.DatabaseSchema.FindTable(String tableName) at Simple.Data.Ado.Schema.Table.GetMaster(String name) at Simple.Data.Ado.AdoAdapterRelatedFinder.TryMasterJoin(String tableName, String relatedTableName) at Simple.Data.Ado.AdoAdapterRelatedFinder.<TryJoin>b__2(Tuple`2 t) at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) at Simple.Data.Ado.AdoAdapterRelatedFinder.TryJoin(String tableName, String relatedTableName) at Simple.Data.Ado.AdoAdapter.IsValidRelation(String tableName, String relatedTableName) at Simple.Data.SimpleRecord.TryGetMember(GetMemberBinder binder, Object& result)
</StackTrace>
</InnerException>
here is the code snippet:
<code>
this is in a webapi controller:
public async Task<Company> Get(int id)
{
var connStr = ConfigurationManager.ConnectionStrings["my-db"].ConnectionString;
var db = Database.OpenConnection(connStr);
Company temp = db.Company.Get(1); // this is getting the right company
Company company = await db.Company.Get(1);
if (company == null)
throw new HttpResponseException(
System.Net.HttpStatusCode.NotFound);
return company;
}
this is from a console client :
public HttpClient CreateClient()
{
var client = new HttpClient();
client.BaseAddress = new Uri(new Uri(_hostUri), "api/companies/");
return client;
}
public Company GetCompany(int id)
{
HttpResponseMessage response;
using (var client = CreateClient())
{
response = client.GetAsync(new Uri(client.BaseAddress, id.ToString())).Result;
}
var result = response.Content.ReadAsStringAsync()
.ContinueWith(c => JsonConvert.DeserializeObject<Company>(c.Result));
return result.Result;
}
</code>
Can anyone help with async stuff? I can also post the github link so that you can play with the code if needed. Thanks
Sabrina