我正在尝试将两个LINQ查询结果与我的DbContext
合并:
var innerJoin = (from pg in context.TbPlageAccueil
join pf in context.TbPermanence on pg.IdPlageAccueil equals pf.IdPlage
where pf.HeureDebPerm > new DateTime(2016, 10, 1) && pf.HeureFinPerm < new DateTime(2016, 12, 31)
select new{ Libelle_Activite = pg.LibellePlageAccueil, Heure_Debut_Activite = pf.HeureDebPerm, Heure_Fin_Activit = pf.HeureFinPerm }).ToList();
var reunion= (from ru in context.TbReunion select new { Libelle_Activite = ru.IntituleReunion, Heure_Debut_Activite = ru.HeureDebRn, Heure_Fin_Activite = ru.HeureFinRn }).ToList();
当我对这两个结果应用联合时,会出现此错误:
CS1929 C#'列表<<匿名类型:字符串Libelle_Activite,DateTime? Activity_Start_Time,DateTime? Time_Fin_Activit >> Queryable.Union << 匿名类型:字符串Libelle_Activite,DateTime? Activity_Start_Time,DateTime? Time_Fin_Activite >>(可查询<< 匿名类型:字符串Activity_Label,DateTime? Activity_Start_Time, 约会时间? Time_Time_Time >>,IEnumerable <<类型匿名:字符串 Activity_Label,DateTime? Time_Time_Time >>,IEnumerable <<类型 匿名:字符串Activity_Label,DateTime? Time_Time_Activity >>, DateEnime? <<匿名类型:字符串Libelle_Activite,DateTime? Time_Debut_Activite,DateTime? Time_End_Activite
我做错了什么? 如何解决这个问题?
答案 0 :(得分:4)
您已经在Heure_Fin_Activit
中定义了属性innerJoin
,而在Heure_Fin_Activite
中定义了属性reunion
。您需要确保它们具有相同的名称和类型:
var reunion= (from ru in context.TbReunion select new
{ Libelle_Activite = ru.IntituleReunion,
Heure_Debut_Activite = ru.HeureDebRn,
Heure_Fin_Activit = ru.HeureFinRn }).ToList();