I am using LINQ with EntityFramewwork 6 and have most of my methods that I need converted to an asynchronous task.
However, I can't figure out why on these two specific scenarios I am getting these design time compile messages. If somebody can explain to me what I need to do to get the task to be asynchronous, it would be much appreciated.
The first type of synchronous task I want to convert is as follows:
public List<Category> GetProjectsByCategoryID(Int16 categoryid)
{
try
{
using (YeagerTechEntities DbContext = new YeagerTechEntities())
{
DbContext.Configuration.ProxyCreationEnabled = false;
DbContext.Database.Connection.Open();
var category = DbContext.Categories.Include("Projects").Where(p => p.CategoryID == categoryid).ToList();
return category;
}
}
catch (Exception ex)
{
throw ex;
}
}
When I try and change the above method to an asynchronous task (see below), I don't know what asynchronous method to place inbetween the "Include("Projects").(p"
public async Task<List<Category>> GetProjectsByCategoryID(Int16 categoryid)
{
try
{
using (YeagerTechEntities DbContext = new YeagerTechEntities())
{
DbContext.Configuration.ProxyCreationEnabled = false;
DbContext.Database.Connection.Open();
var category = await DbContext.Categories.Include("Projects").(p => p.CategoryID == categoryid);
return category;
}
}
catch (Exception ex)
{
throw ex;
}
}
How can I convert this synchronous method into an asynchronous method?
public List<CustomerEmail> GetCustomerDropDownList()
{
try
{
using (YeagerTechEntities DbContext = new YeagerTechEntities())
{
DbContext.Configuration.ProxyCreationEnabled = false;
DbContext.Database.Connection.Open();
var customers = DbContext.Customers.Select(s =>
new CustomerEmail()
{
CustomerID = s.CustomerID,
Email = s.Email
}).ToList();
return customers;
}
}
catch (Exception ex)
{
throw ex;
}
}