【发布时间】:2017-03-20 09:31:31
【问题描述】:
我有一个 ASP.NET Core 项目和现有数据库 (MS SQLServer)。我已经有来自 db 的脚手架模型:
组件.cs
public partial class
{
public Component()
{
ComponentDocumentationLink = new HashSet<ComponentDocumentationLink>();
}
public int IdConponent { get; set; }
public string ComponentName { get; set; }
public string ComponentTitle { get; set; }
public string ComponentDescription { get; set; }
public int IdComponentType { get; set; }
public int IdrecStatus { get; set; }
public DateTime CreateDate { get; set; }
public string CreateUser { get; set; }
public string ChangeUser { get; set; }
public DateTime? ChangeDate { get; set; }
public virtual ICollection<ComponentDocumentationLink> ComponentDocumentationLink { get; set; }
public virtual ComponentType IdComponentTypeNavigation { get; set; }
}
ComponentType.cs
public partial class ComponentType
{
public ComponentType()
{
Component = new HashSet<Component>();
}
public int IdComponentType { get; set; }
public string ComponentTypeName { get; set; }
public int IdrecStatus { get; set; }
public DateTime CreateDate { get; set; }
public string CreateUser { get; set; }
public string ChangeUser { get; set; }
public DateTime? ChangeDate { get; set; }
public virtual ICollection<Component> Component { get; set; }
}
ComponentDocumentationLink.cs
public partial class ComponentDocumentationLink
{
public int IdComponentDocumentationLink { get; set; }
public int IdComponent { get; set; }
public int IdDocumentation { get; set; }
public int IdrecStatus { get; set; }
public DateTime CreateDate { get; set; }
public string CreateUser { get; set; }
public string ChangeUser { get; set; }
public DateTime? ChangeDate { get; set; }
public virtual Component IdComponentNavigation { get; set; }
public virtual Documentation IdDocumentationNavigation { get; set; }
}
和 Documentation.cs
public partial class Documentation
{
public Documentation()
{
ComponentDocumentationLink = new HashSet<ComponentDocumentationLink>();
}
public int IdDocumentation { get; set; }
public int IdDocumentationType { get; set; }
public string DocumentationSrc { get; set; }
public int IdrecStatus { get; set; }
public DateTime CreateDate { get; set; }
public string CreateUser { get; set; }
public string ChangeUser { get; set; }
public DateTime? ChangeDate { get; set; }
public virtual ICollection<ComponentDocumentationLink> ComponentDocumentationLink { get; set; }
public virtual DocumentationType IdDocumentationTypeNavigation { get; set; }
}
问题是我在组件和文档之间有链接表 ComponentDocumentationLink(多对多关系),而在 Component 和 ComponentType 之间没有表(一对一关系)。
当我尝试为控制器中的每个组件获取 ComponentType 时,var components = db.Component.Include(ct => ct.IdComponentTypeNavigation); 没有问题,但没有使用此查询从文档中检索每个组件的数据。
【问题讨论】:
标签: c# asp.net linq asp.net-core