当前位置: 代码迷 >> SharePoint >> Linq To SharePoint有关问题
  详细解决方案

Linq To SharePoint有关问题

热度:146   发布时间:2016-05-02 07:02:49.0
Linq To SharePoint问题
现有两个表:
Employee表: ID, EmployeeName, Age, Gender
Education Information 表:EmployeeID(lookup类型),EmployeeID: EmployeeName(附加列),Major(Choice类型)
用“SPMetal”生成了实体类,使用Linq To SharePoint时出现以下问题:
1. 编写如下代码,join会报错
                var query = from c in dataContext.Employee
                            join g in dataContext.EducationInformation on c.Id equals g.EmployeeID
                            where g.Major == "Financial"
                            select new
                            {
                                c.EmployeeName
                            };
原因分析:C.Id被解析成Int? 类型,但是g.EmployeeID类型为EmployeeItem类型,两者类型不匹配,导致出现“The type of one of the expression I the join clause is incorrect. Type inference failed in the call to ‘Join’”错误。
2.Where g.Major ==“Finanical”报错,因为g.Major的类型为“Major?”,不能直接与字符串相等。

请问下各位,针对以上两个问题,有没有什么好的解决方法?
------解决方案--------------------
Linq,很高级啊,围观一下
------解决方案--------------------
在join的时候做一下类型转换啊。 你试了吗?  就在你的语句里就可以。
------解决方案--------------------
加括号强转一下试试
------解决方案--------------------
参考
  相关解决方案