odata的导航属性问题

时间:2016-03-29 14:46:29

标签: c# linq

我有一个名为ProjectViewModel的视图模型和名为Project的普通模型..所以我通过linq查询填充ProjectViewModel。

但返回错误

  

' ObjectContent`1'类型无法序列化内容类型的响应主体' application / json;的OData = minimalmetadata;流= TRUE;字符集= UTF-8'""类型":" System.InvalidOperationException""堆栈跟踪":"&#34 ;," internalexception":{           "消息":"未找到NavigationLink工厂的导航属性'订阅'来自实体类型' SSAStatusService.Domain.ViewModel.ProjectViewModel'在实体集'项目'。尝试在EntitySetConfiguration上调用HasNavigationPropertyLink。\ r \ nParameter name:navigationProperty

以下是我的课程

 public class ProjectViewModel
{
   public String ProjectId { get; set; }

   public String Name { get; set; }

   public List<Subscriptions> Subscriptions { get; set; }

}

public class Subscriptions
{
    public long Id { get; set; }

    [MaxLength(40)]
    public string ProjectId { get; set; }

    public string SubscriptionId { get; set; }
}

var query=from p in DataContext.Project 
      join c in DataContext.Subscriptions on p.ProjectId equals c.ProjectId into subs
      select new ProjectViewModel { 
                                    ProjectId = p.ProjectId,
                                    Name = p.Name,
                                    Subscriptions=subs.ToList()
                                  };

0 个答案:

没有答案