C# Linq单机器人不返回我的对象
我在我的android项目中使用这个:C# Linq单机器人不返回我的对象,c#,linq,xamarin.android,azure-mobile-services,C#,Linq,Xamarin.android,Azure Mobile Services,我在我的android项目中使用这个: private readonly IMobileServiceTable<Product> table; ... table = serviceClient.GetTable<Product>(); ... List<Product> _items = this.table.Where(x => x.Id == p.Id).ToListAsync().Result; private只读imobileservice
private readonly IMobileServiceTable<Product> table;
...
table = serviceClient.GetTable<Product>();
...
List<Product> _items = this.table.Where(x => x.Id == p.Id).ToListAsync().Result;
private只读imobileservice表;
...
table=serviceClient.GetTable();
...
List _items=this.table.Where(x=>x.Id==p.Id).toListSync().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;
List\u items=this.table.Select(x=>newproduct(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)),其中(x=>x.Id==p.Id.toListSync().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
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Runtime.Serialization;
使用系统集合;
使用系统组件模型;
使用System.IO;
使用Microsoft.WindowsAzure.MobileServices;
使用Catalog.Core.Tools;
命名空间Catalog.Core.Business
{
///
///描述azure数据库中的对象产品
///
公共类产品:INotifyPropertyChanged
{
#地区活动
公共事件属性更改事件处理程序属性更改;
//创建OnPropertyChanged方法以引发事件
受保护的void OnPropertyChanged(字符串名称)
{
PropertyChangedEventHandler处理程序=PropertyChanged;
if(处理程序!=null)
{
处理程序(此,新PropertyChangedEventArgs(名称));
}
}
#端区
#区域属性
///
///获取或设置id。
///
///
///身份证。
///
私有int-id;
公共整数Id
{
获取{return id;}
设置
{
id=值;
OnPropertyChanged(“Id”);
}
}
///
///获取或设置名称。
///
///
///名字。
///
公共字符串名称{get;set;}
///
///获取或设置描述。
///
///
///描述。
///
公共字符串说明{get;set;}
///
///获取或设置宽度。
///
///
///宽度。
///
公共十进制宽度{get;set;}
///
///获取或设置高度。
///
///
///高度。
///
公共十进制高度{get;set;}
///
///获取或设置深度。
///
///
///深度。
///
公共十进制深度{get;set;}
///
///获取或设置维度单位。
///
///
///尺寸单位。
///
公共字符串维度sunit{get;set;}
///
///获取或设置权重。
///
///
///重量。
///
公共十进制权重{get;set;}
///
///获取或设置重量单位。
///
///
///重量单位。
///
公共字符串权重单元{get;set;}
///
///获取或设置价格。
///
///
///价格。
///
公共十进制价格{get;set;}
///
///获取或设置小图片。
///
///
///小图片。
///
公共字符串SmallPic{get;set;}
///
///获取或设置大图片。
///
///
///大照片。
///
私有字符串bigpic;
公共字符串BigPic
{
获取{return bigpic;}
设置
{
if(bigpic!=值)
{
bigpic=值;
OnPropertyChanged(“BigPic”);
}
}
}
///
///获取或设置添加的时间。
///
///
///增加的时间。
///
公共整数加法时间{get;set;}
公共字符串FormatDimensions{get{返回this.Width+“x”+this.Height+“x”+this.Depth+this.DimensionsUnit;}}
公共字符串FormatWeight{get{返回this.Weight+this.WeightUnit;}}
公共字符串格式AddedTime{get{return Tools.DateSystem.UnixTimeStampToDateTime(this.AddedTime.ToString();}}
#端区
#区域构造函数
/*不删除-序列化*/
公共产品(){}
///
///初始化类的新实例。
///
///名字。
///描述。
///宽度。
///高度。
///深度。
///尺寸单位。
///重量。
///重量单位。
///价格。
///小图片。
///大照片。
///增加的时间。
///
///无效价格
///或
///无效重量
///或
///无效宽度
///或
///无效高度
///或
///无效深度
///
公共产品(整数id、字符串名称、字符串描述、十进制宽度、十进制高度、十进制深度、字符串尺寸单位、十进制重量、字符串重量单位、十进制价格、字符串小图片、字符串大图片、整数加时间)
{
这个.Id=Id;
this.Name=Name;
这个。描述=描述;
这个。宽度=宽度;
这个。高度=高度;
这个。深度=深度;
this.DimensionsUnit=DimensionsUnit;
这个。重量=重量;
this.WeightUnit=WeightUnit;
这个。价格=价格;
this.SmallPic=SmallPic;
this.BigPic=BigPic;
this.AddedTime=AddedTime;
}
公共图像()
{
返回