我在我的android项目中使用它:
private readonly IMobileServiceTable<Product> table;
...
table = serviceClient.GetTable<Product>();
...
List<Product> _items = this.table.Where(x => x.Id == p.Id).ToListAsync().Result;
我的项目存在于表格中。并且结果(_items)的所有字段都是空的,除了正确的id值。
如果我这样做:
List<Product> _items = this.table.Select(x => new Product(x.Id, x.Name, x.Description, x.Width, x.Height, x.Depth, x.DimensionsUnit, x.Weight, x.WeightUnit, x.Price, x.SmallPic, x.BigPic, x.AddedTime)).Where(x => x.Id == p.Id).ToListAsync().Result;
一切都好......
这是我的产品类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Collections;
using System.ComponentModel;
using System.IO;
using Microsoft.WindowsAzure.MobileServices;
using Catalog.Core.Tools;
namespace Catalog.Core.Business
{
/// <summary>
/// Describe the object Product in the azure database
/// </summary>
public class Product : INotifyPropertyChanged
{
#region EVENTS
public event PropertyChangedEventHandler PropertyChanged;
// Create the OnPropertyChanged method to raise the event
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
#endregion
#region ATTRIBUTES
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>
/// The id.
/// </value>
private int id;
public int Id
{
get { return id; }
set
{
id = value;
OnPropertyChanged("Id");
}
}
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>
/// The name.
/// </value>
public String Name { get; set; }
/// <summary>
/// Gets or sets the description.
/// </summary>
/// <value>
/// The description.
/// </value>
public String Description { get; set; }
/// <summary>
/// Gets or sets the width.
/// </summary>
/// <value>
/// The width.
/// </value>
public Decimal Width { get; set; }
/// <summary>
/// Gets or sets the height.
/// </summary>
/// <value>
/// The height.
/// </value>
public Decimal Height { get; set; }
/// <summary>
/// Gets or sets the depth.
/// </summary>
/// <value>
/// The depth.
/// </value>
public Decimal Depth { get; set; }
/// <summary>
/// Gets or sets the dimensions unit.
/// </summary>
/// <value>
/// The dimensions unit.
/// </value>
public String DimensionsUnit { get; set; }
/// <summary>
/// Gets or sets the weight.
/// </summary>
/// <value>
/// The weight.
/// </value>
public Decimal Weight { get; set; }
/// <summary>
/// Gets or sets the weight unit.
/// </summary>
/// <value>
/// The weight unit.
/// </value>
public String WeightUnit { get; set; }
/// <summary>
/// Gets or sets the price.
/// </summary>
/// <value>
/// The price.
/// </value>
public Decimal Price { get; set; }
/// <summary>
/// Gets or sets the small pic.
/// </summary>
/// <value>
/// The small pic.
/// </value>
public String SmallPic { get; set; }
/// <summary>
/// Gets or sets the big pic.
/// </summary>
/// <value>
/// The big pic.
/// </value>
private String bigpic;
public String BigPic
{
get { return bigpic; }
set
{
if (bigpic != value)
{
bigpic = value;
OnPropertyChanged("BigPic");
}
}
}
/// <summary>
/// Gets or sets the added time.
/// </summary>
/// <value>
/// The added time.
/// </value>
public int AddedTime { get; set; }
public String FormatDimensions { get { return this.Width + "x" + this.Height + "x" + this.Depth + this.DimensionsUnit; } }
public String FormatWeight { get { return this.Weight + this.WeightUnit; } }
public String FormatAddedTime { get { return Tools.DateSystem.UnixTimeStampToDateTime(this.AddedTime).ToString(); } }
#endregion
#region CONSTRUCTOR
/* DO NOT REMOVE - SERIALIZATION */
public Product() { }
/// <summary>
/// Initializes a new instance of the <see cref="Product"/> class.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="description">The description.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="depth">The depth.</param>
/// <param name="dimensionsUnit">The dimensions unit.</param>
/// <param name="weight">The weight.</param>
/// <param name="weightUnit">The weight unit.</param>
/// <param name="price">The price.</param>
/// <param name="smallPic">The small pic.</param>
/// <param name="bigPic">The big pic.</param>
/// <param name="addedTime">The added time.</param>
/// <exception cref="System.IndexOutOfRangeException">
/// Invalid price
/// or
/// Invalid weight
/// or
/// Invalid width
/// or
/// Invalid height
/// or
/// Invalid depth
/// </exception>
public Product(int id, String name, String description, Decimal width, Decimal height, Decimal depth, String dimensionsUnit, Decimal weight, String weightUnit, Decimal price, String smallPic, String bigPic, int addedTime)
{
this.Id = id;
this.Name = name;
this.Description = description;
this.Width = width;
this.Height = height;
this.Depth = depth;
this.DimensionsUnit = dimensionsUnit;
this.Weight = weight;
this.WeightUnit = weightUnit;
this.Price = price;
this.SmallPic = smallPic;
this.BigPic = bigPic;
this.AddedTime = addedTime;
}
public Boolean HasImage()
{
return (SmallPic != null);
}
#endregion
}
}
我不明白为什么不在哪里构建对象,也不知道在哪里查找以便找到什么hapenning。 谢谢!