在Code First中重用linq到sql的存储过程结果

时间:2013-10-12 05:47:43

标签: c# linq entity-framework linq-to-sql

我想获得Stored Procedure查询

var labratorySerialFinalResult = repository.UoW.Orm.Database.SqlQuery<SPLabratorySerialFinalResult>("EXECUTE LabratorySerialFinalResult @OrderNo='" + project.OrderNumber + "'")

并使用如下结果:

 var result = projSerials.Where(x =>!labratorySerialFinalResult.Any(v => v.SerialNo == x.SerialNo)
.Union(labratorySerialFinalResult.Where(c => c.FinalResult == "Reject");

但是我遇到以下异常:

Unable to create a constant value of type SPLabratorySerialFinalResult Only primitive types or enumeration types are supported in this context.

1 个答案:

答案 0 :(得分:0)

var labratorySerialFinalResult = repository.UoW.Orm.Database.SqlQuery<SPLabratorySerialFinalResult>("EXECUTE LabratorySerialFinalResult @OrderNo='" + project.OrderNumber + "'").AsEnumerable();

var result = projSerials.AsEnumerable().Where(x =>!labratorySerialFinalResult.Any(v => v.SerialNo == x.SerialNo)
          .Union(labratorySerialFinalResult.Where(c => c.FinalResult == "Reject");

Referencing Non-Scalar Variables Not Supported

  

在查询中引用非标量变量(例如实体)   不支持。执行此类查询时,会出现NotSupportedException   抛出异常,并显示一条消息,指出“无法创建一个   EntityType类型的常量值。只有原始类型('如   在此上下文中支持Int32,String和Guid'。“