2
我有3個表:讀取數據
表:人
public string Id { get; set; }
[JsonProperty(PropertyName = "firstName")]
public string FirstName { get; set; }
[JsonProperty(PropertyName = "secondName")]
public string SecondName { get; set; }
表:汽車
public string Id { get; set; }
[JsonProperty(PropertyName = "Name")]
public string CarName { get; set; }
表:ManCar
public string Id { get; set; }
[JsonProperty(PropertyName = "manId")]
public string ManId { get; set; }
[JsonProperty(PropertyName = "carId")]
public string CarId { get; set; }
C#從Azure代碼讀取日期:
public async Task<IEnumerable<String>> GetAllCarsByMan(Man man)
{
MobileServiceCollection<ManCar, ManCar> data;
IMobileServiceTable<ManCar> dataTable = App.MobileService.GetTable<ManCar>();
try
{
data = await dataTable
.Where(item => item.ManId == man.Id).Select(menuItem => menuItem.CarId)
.ToCollectionAsync();
}
catch (MobileServiceInvalidOperationException ex)
{
Tools.errorList.AddMessage("AzureDataProvider.LoadData" + ex.ToString());
}
return data;
}
public async Task<IEnumerable<Car>> GetAllCarsForAllMen()
{
List<Car> listOfCars = new List<Car>();
MobileServiceCollection<Man, Man> data;
IMobileServiceTable<Man> dataTable = App.MobileService.GetTable<Man>();
try
{
data = await dataTable.Where.ToCollectionAsync();
foreach (var man in data)
{
var cars = await GetAllCarsByMan(Man man);
if (cars.Count>0)
{
IMobileServiceTable<Car> dataCar = App.MobileService.GetTable<Car>();
foreach (var car in cars)
{
data = await dataTable.Where(item => item.Id == car).ToCollectionAsync();
if(data[0]!=null)
{
listOfCars.Add(data[0]);
}
}
}
}
}
catch (MobileServiceInvalidOperationException ex)
{
Tools.errorList.AddMessage("AzureDataProvider.LoadData" + ex.ToString());
}
return listOfCars;
}
public async Task<IEnumerable<String>> GetAllCarsByMan(Man man)
{
MobileServiceCollection<ManCar, ManCar> data;
IMobileServiceTable<ManCar> dataTable = App.MobileService.GetTable<ManCar>();
try
{
data = await dataTable
.Where(item => item.ManId == man.Id).Select(menuItem => menuItem.CarId)
.ToCollectionAsync();
}
catch (MobileServiceInvalidOperationException ex)
{
Tools.errorList.AddMessage("AzureDataProvider.LoadData" + ex.ToString());
}
return data;
}
當我試圖從這些平板電腦中獲取數據時,它非常緩慢。如何使用AzureMobileServices從此表中讀取數據?