【发布时间】:2020-04-13 00:08:48
【问题描述】:
我有以下表结构:
public class Delegate {
public int DelegateId {get;set;}
public int? NotificationTypeId { get; set; }
public NotificationType NotificationType { get; set; }
}
public class TrainingNotification {
public int TrainingNotificationId {get;set;}
public int NotificationTypeId {get;set;}
public int DelegateId {get;set;}
public virtual Delegate Delegate {get;set;}
}
Delegate 和 TrainingNotification 之间的一对多
public class NotificationType {
public int NotificationTypeId {get;set;}
public virtual ICollection<Delegate> Delegates {get;set;}
}
想要在 Delegate 中检索 NotificationTypeId 的 TrainingNotification。
var delegates21 = await from tn in _context.TrainingNotification
join cd in _context.Delegate on
new { tn.DelegateId, tn.NotificationTypeId } equals
new { cd.DelegateId, cd.NotificationTypeId }
但出现错误 连接子句中的表达式之一的类型不正确
谁能帮助解决这个问题?
这是测试数据和预期结果:
Delegate:
DelegateId NotificationTypeId
100 1
8201 2
101 null
TrainginNotification:
TrainignNotificationId DelegateId NotificationTypeId
1 8201 1
2 8201 2
3 100 1
NotificationType:
NotificationTypeId Name
1 InviteEmail
2 ReminderEmail
Retrieve users who hasnt got reminder emails:
Result:
DelegateId
100
谢谢
【问题讨论】:
标签: c# linq-to-sql entity-framework-core-2.1