简体   繁体   English

具有实体和RIA Services / Silverlight的自定义类

[英]Custom class with an entity and RIA Services/Silverlight

I have a class with looks like this: 我有一堂课,看起来像这样:

[DataContract]
public class TestBatchWithHistoryResult
{
    [Key]
    [DataMember]
    public int Id { get; set; }
    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public string Description { get; set; }
    [DataMember]
    public string LastRequestedBy { get; set; }
    [DataMember]
    public DateTime? LastRun { get; set; }
    [DataMember]
    public Collection<string> LastConfigurations { get; set; }
    [DataMember]
    public TestBatch Entity { get; set; }
}

When I build the website and Silverlight project and find that the Entity property is not created in the "auto-generated" code on the Silverlight side, but all the other properties are present. 当我构建网站和Silverlight项目时,发现未在Silverlight端的“自动生成”代码中创建Entity属性,但是所有其他属性都存在。

What could be preventing the Entity property from being created? 是什么会阻止Entity属性的创建?

Thanks 谢谢

Michael 麦可

For child entities to be created on the client-side, you need to have a service method exposing that entity type on the server side, eg: 对于要在客户端创建的子实体,您需要一种服务方法在服务器端公开该实体类型,例如:

public IQueryable<TestBatch> GetTestBatches(){}

And you also need to have the Include attribute on the property: 而且您还需要在该属性上具有Include属性:

[Include]
public TestBatch Entity {get; set;}

If the data contract is not referenced by any of your services, it will not be present. 如果您的任何服务都未引用该数据合同,则该合同将不存在。 Only referenced data contracts are generated. 仅生成引用的数据合同。 If it is not referenced but it should be (ie if it is a type inherited from one that is returned, and will be returned at some point) use the ServiceKnowTypeAttribute to declare it at the beginning of you service contract. 如果未引用它,但是应该引用它(即,如果它是从返回的继承的类型,并将在某个时候返回),请在服务合同开始时使用ServiceKnowTypeAttribute对其进行声明。

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

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