简体   繁体   English

移动服务查询例外

[英]Mobile Services query exception

When I use code with generic: 当我使用泛型代码时:

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

where TParent: IEnity 其中TParent:IEnity

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

I catch the exception: 我抓住了异常:

The member 'Id' is not supported in the 'Where' Mobile Services query expression 'Convert(prnt).Id'. 'Where'移动服务查询表达式'Convert(prnt).Id'不支持成员'Id'。

But if I change the generic to type: 但是,如果我将通用更改为类型:

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

I have normal result. 我的结果很正常。 Why? 为什么? And how can I use generic? 我怎样才能使用通用?

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

where T : class, IEnity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM