在 Silverlight 域服务中包含子实体集合
我有一个域服务类,如下所示
[MetadataTypeAttribute(typeof(Question.QuestionMetadata))]
public partial class Question
{
internal sealed class QuestionMetadata
{
private QuestionMetadata()
{
}
[Include]
public EntityCollection<Answer> Answers { get; set; }
public EntityCollection<AssignmentsQuestionsMapping> AssignmentsQuestionsMappings { get; set; }
public int Marks { get; set; }
public string QuestionDescription { get; set; }
public long QuestionID { get; set; }
public string QuestionTitle { get; set; }
public EntityCollection<UserQuestionAnsweredMapping> UserQuestionAnsweredMappings { get; set; }
}
}
并且我在域服务中有以下查询
public IQueryable<Question> GetQuestionsByAssignmentId(long assignmentId)
{
var questions = from q in this.ObjectContext.Questions.Include("Answers")
join qam in this.ObjectContext.AssignmentsQuestionsMappings on q.QuestionID equals qam.QuestionID
join assign in this.ObjectContext.Assignments on qam.AssignmentID equals assign.AssignmentID
where assign.AssignmentID == assignmentId
select q;
return questions;
}
据我所知,如果您想在域服务查询中包含子实体,那么您可以在实体的元数据文件中设置 [Include] 属性并将其包含在通过 .Include("ChildEntityCollectionName") 查询。
我已经完成了这两个操作,但我仍然没有在客户端收到 ChildEntity Collection。 我缺少什么?
I have a Domain Service class as below
[MetadataTypeAttribute(typeof(Question.QuestionMetadata))]
public partial class Question
{
internal sealed class QuestionMetadata
{
private QuestionMetadata()
{
}
[Include]
public EntityCollection<Answer> Answers { get; set; }
public EntityCollection<AssignmentsQuestionsMapping> AssignmentsQuestionsMappings { get; set; }
public int Marks { get; set; }
public string QuestionDescription { get; set; }
public long QuestionID { get; set; }
public string QuestionTitle { get; set; }
public EntityCollection<UserQuestionAnsweredMapping> UserQuestionAnsweredMappings { get; set; }
}
}
And I have following query in Domain Service
public IQueryable<Question> GetQuestionsByAssignmentId(long assignmentId)
{
var questions = from q in this.ObjectContext.Questions.Include("Answers")
join qam in this.ObjectContext.AssignmentsQuestionsMappings on q.QuestionID equals qam.QuestionID
join assign in this.ObjectContext.Assignments on qam.AssignmentID equals assign.AssignmentID
where assign.AssignmentID == assignmentId
select q;
return questions;
}
As far as I know if you want to include child entity in domain service query, then you have Set [Include] attribute in metadata file for entity and include it in query by .Include("ChildEntityCollectionName").
I have done both of them, but still I am not receiving ChildEntity Collection at my client side.
What am I missing ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你快到了。您需要添加关联属性来帮助 WCF RIA 了解
Question
和Answer
是如何关联的。这假设您的实体共享外键。
您可以通过RIA服务查看更多信息:插入多个演示模型对象
You are almost there. You need to add an association attribute to help WCF RIA understand how
Question
andAnswer
are related.This assumes your entities share a foreign key.
You can see more information with RIA Services: Inserting multiple presentation-model objects