asp.net - LINQ 使用不同数据类型的连接
问题描述
我在两个表约会和服务之间有关系,当 Id(Int) 等于约会表中的服务列时,我想从服务表中查看名称
public class Appointments
{
public virtual Services Service { get; set; }
}
public class UsersViewModels
{
public Services services { get; set; }
public Appointments appointments { get; set; }
}
控制器:
// GET
public ActionResult Index( Services services, Appointments appointments)
{
var username = (from emp in db.Appointments
join w in db.Services on emp.Service equals w.Id
select new UsersViewModels
{
appointments = emp,
services= w.UserName,
});
return View(username);
}
看法:
@item.appointments.Service.Name
如何将服务类型转换为 Int?
解决方案
我想你可以使用下面的代码,
与之比较emp.Service.Id equals w.Id
var username = (from emp in db.Appointments
join w in db.Services on emp.Service.Id equals w.Id
select new UsersViewModels
{
appointments = emp,
services = w.UserName,
});
推荐阅读
- flutter - 每次 Navigator.push 到下一页时调用的回调
- matplotlib - 在对数比例图上绘制 png 作为背景
- html - 当 [ngStyle] 添加样式时,角度动画不起作用
- elasticsearch - ElasticSearch:查询每个类别的N个项目
- python - 日期计算[加减天数]
- reactjs - 无法在我的项目中解析“react-native”
- java - 如何使用 JSTL 标签库在 Spring Boot 中显示图像?
- javascript - 使用正则表达式替换字符串的一部分
- haskell - 使用 scotty 从 POST 请求执行 shell 脚本
- java - Hibernate:将类持久化为接口