DataContext db = new DataContext();
Select_Utilities SelectedUtility = (from su in db.Select_Utilities
where su.id == SelectUtilityId
&& su.Worksite_Id == WorksiteId
&& su.Utility_Company.id == UtilityCompanyId
select su).FirstOrDefault();
然后我想说SelectedUtility.comment =“无论评论是什么”;
但是获得错误:不能将'Select_Utility'类型转换为'Select_Utilities'
在声明中使用'FirstOrDefault'任何建议吗?
由于
答案 0 :(得分:3)
将结果类型更改为Select_Utility
Select_Utility SelectedUtility = // here
(from su in db.Select_Utilities
where su.id == SelectUtilityId &&
su.Worksite_Id == WorksiteId &&
su.Utility_Company.id == UtilityCompanyId
select su).FirstOrDefault();
答案 1 :(得分:1)
我猜Select_Utilities
是您的Entity表的名称,它返回Select_Utility
个对象的集合。试试:
Select_Utility selectedUtility = (from su in db.Select_Utilities
where su.id == SelectUtilityId
&& su.Worksite_Id == WorksiteId
&& su.Utility_Company.id == UtilityCompanyId
select su).FirstOrDefault();