Linq到Sql的转换每次都为null
本文关键字:null 转换 Sql Linq | 更新日期: 2023-09-27 18:06:30
我的SQL查询为:
select * from EH_PP_TeacherObservations tos
join account acc on tos.EH_PP_TeacherAcctId = acc.id
join EH_PP_ObserverStatus os on tos.EH_PP_TeacherAcctId = os.EH_PP_AcctId
join [dbo].[EH_PP_TeacherObservationStatusesRefTable] tosrt on tos.[EH_PP_TOSRT_TeacherObservationStatusIDEH] = tosrt.[EH_PP_TOSRT_TeacherObservationStatusID]
where tos.[EH_PP_TOSRT_TeacherObservationStatusIDEH] = 'A717732D-68FA-47FE-A354-C2CB589F29FA' and os.[EH_PP_O_isObserver]= 1
我想把它转换成LINQ。
我尝试如下:
list = (
from a in context.EH_PP_TeacherObservations
join b in context.accounts on a.EH_PP_TeacherAcctId equals b.id
join c in context.EH_PP_ObserverStatus on a.EH_PP_TeacherAcctId equals c.EH_PP_AcctId
join d in context.EH_PP_TeacherObservationStatusesRefTables on a.EH_PP_TOSRT_TeacherObservationStatusIDEH equals d.EH_PP_TOSRT_TeacherObservationStatusID
where a.EH_PP_TOSRT_TeacherObservationStatusIDEH == new Guid("A717732D-68FA-47FE-A354-C2CB589F29FA")
&& c.EH_PP_O_isObserver == true
select new Entity.Observations
{
FullName = (b.firstName + " " + b.lastName),
EH_PP_ObservationID = Guid.Parse(a.EH_PP_ObservationID.ToString()),
EH_PP_TE_TeacherEvalID = Guid.Parse(a.EH_PP_TE_TeacherEvalID.ToString()),
EH_PP_TOT_ObservationStartDateTime = a.EH_PP_TOT_ObservationStartDateTime,
EH_PP_TOT_ObservationEndDateTime = a.EH_PP_TOT_ObservationEndDateTime,
EH_PP_TOT_Announced = int.Parse(a.EH_PP_TOT_Announced.ToString()),
EH_PP_TOT_ObservationNum = a.EH_PP_TOT_ObservationNum.ToString(),
EH_PP_TeacherAcctId = a.EH_PP_TeacherAcctId.ToString(),
EH_PP_ObserverAcctID = Guid.Parse(a.EH_PP_ObserverAcctID.ToString()),
EH_PP_TOSRT_TeacherObservationStatusIDEH = a.EH_PP_TOSRT_TeacherObservationStatusIDEH.ToString()
}
).ToList<Entity.Observations>();
但它显示我是无效的。
请帮帮我。
问题出现在where语句中:a.EH_PP_TOSRT_eacherObservationStatusDEH不等于新的Guid("A717732D-68FA-47FE-A354-C2CB589F29FA"(try Convert.ToString(a.EH_PP_TORT_TeacherObservationStatusIDEH(.ToUpper((="A717732D-68FA-47FE-A354-C2CB589F29FA">
注意:Guid是struct,所以比较C#中的struct很麻烦,如果您的对象具有相同的值,equals总是返回false。