asp.net - 如何从两个相关表中创建一个列表
问题描述
嗨,我有表模型以及订单和状态之间的一对多关系
我想按顺序显示所有属性的列表,并根据订单 ID 显示状态中的最后一个标题,以便我如何获得它?谢谢你
这是我的代码:
namespace Pur.Models
{
using System;
using System.Collections.Generic;
public partial class Order
{
public int OrdeId { get; set; }
public Nullable<int> UserID { get; set; }
public Nullable<System.DateTime> OrderDate { get; set; }
public string Description { get; set; }
public int Quantity { get; set; }
public string Unit { get; set; }
public string Priority { get; set; }
public string Department { get; set; }
public virtual ICollection<Status> Status { get; set; }
}
}
和另一个:
namespace Pur.Models
{
using System;
using System.Collections.Generic;
public partial class Status
{
public int StatusId { get; set; }
public string Title { get; set; }
public int OrderID { get; set; }
public Nullable<System.DateTime> StatusDate { get; set; }
public virtual Order Order { get; set; }
}
解决方案
您可以创建连接查询,然后将其传递给新模型
var query = your query
var Lists = db.Database.SqlQuery<OrderModel>(query);
推荐阅读
- javascript - 尝试自定义此正则表达式以提取医疗报告结果
- arrays - 如何根据内容删除 Ruby 数组中的项目?
- javascript - 在 some_object 为空/未定义时调用 some_object?.method() (TypeScript)
- java - 如何解决 TomEE 8.x、Hibernate 5.4 和 Java 8 的 ASM 问题?
- google-chrome - 如何避免 Chrome 的自动下载限制
- ios - 从 UITabbarController 中选择选项卡时如何更新 VC 中的值?
- python-3.x - 如何使用图章在海龟中创建形状?
- html - Python Selenium 无法找到迭代跨度类的文本
- reactjs - ReactJS:如何通过链接传递函数到另一个组件?
- assembly - 为什么 MOV AX,数据有效?