1
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”....有什么建议吗?

谢谢

4

2 回答 2

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();
于 2013-03-11T13:13:41.777 回答
1

我猜Select_Utilities是你的实体表的名称,它包含一组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();
于 2013-03-11T13:14:00.867 回答