移动服务查询例外

时间:2013-06-21 11:46:18

标签: c# azure azure-mobile-services

当我使用泛型代码时:

    var parenttable = MobileService.GetTable<TParent>();
    var testid = await parenttable.Where(prnt => prnt.Id == 20).ToListAsync();

其中TParent:IEnity

public interface IEnity
{
    int Id { get; set; }
}

我抓住了异常:

  

'Where'移动服务查询表达式'转换(prnt).Id'不支持成员'Id'。

但是,如果我将通用更改为type:

   var parenttable = MobileService.GetTable<Category>();
   var testid = await parenttable.Where(prnt => prnt.Id == 20).ToListAsync();

我的结果很正常。 为什么?我怎样才能使用泛型?

1 个答案:

答案 0 :(得分:8)

知道这是一个老问题,但答案是你必须告诉这个泛型类型也是一个类。

where T : class, IEnity