日期:2014-05-20  浏览次数:20756 次

在WCF RIA中的linq语句中调用存储过程做条件判断,提示无法识别改函数
我在WCF RIA中的linq查询语句中调用存储过程来作为where的条件判断,在运行时提示无法识别该存储过程。有没有大侠遇到过这种问题,劳烦解答!
代码如下:

public IQueryable<ProMainenance> getMyProMainenances(string userName)
        {
            return (from s in this.ObjectContext.ProMainenances
                    where s.auditID == userName ||
                        (from c in this.ObjectContext.LoginUsers
                         where c.ZT == true && c.InUserID == userName && c.UserId == s.auditID
                         select c).Count() > 0 ||
                         isAvaiable(s.Vehiclenum)
                        (from c in this.ObjectContext.proc_Vehiclerights(userName)
                        where s.Vehiclenum == c.Vehiclenum
                        select c
                        ).Count() > 0
                    select s);
        }

错误消息如下:
引用
Load operation failed for query 'getMyProMainenances_Check'. LINQ to Entities 不识别方法“System.Data.Objects.ObjectResult`1[VehicleRIAServicesLibrary.Web.InfoVehicle] proc_Vehiclerights(System.String)”,因此该方法无法转换为存储表达式。
linq 无法转为存储表达式 不识别方法

------解决方案--------------------
 (from c in this.ObjectContext.proc_Vehiclerights(userName)
                        where s.Vehiclenum == c.Vehiclenum
                        select c
                        ).Count() > 0


这些可以简化成一句: 
this.ObjectContext.proc_Vehiclerights(userName).AsEnumerable().Any(c=>s.Vehiclenum == c.Vehiclenum)