无法使用Linq将存储过程的输出绑定到gridview

时间:2012-05-10 13:25:27

标签: .net linq c#-4.0

DBML Designer中的代码


[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.uspCalculateRiskMatrix")]   
      public int uspCalculateRiskMatrix([global::System.Data.Linq.Mapping.ParameterAttribute(Name="CashPrice", DbType="Float")] System.Nullable cashPrice,     [global::System.Data.Linq.Mapping.ParameterAttribute(Name="InputAPH", DbType="Int")] System.Nullable inputAPH,    [global::System.Data.Linq.Mapping.ParameterAttribute(Name="Bushels", DbType="Int")] System.Nullable bushels,     [global::System.Data.Linq.Mapping.ParameterAttribute(Name="PercentageCover", DbType="Float")] System.Nullable percentageCover,    [global::System.Data.Linq.Mapping.ParameterAttribute(Name="BasicEstimate", DbType="Float")] System.Nullable basicEstimate,     [global::System.Data.Linq.Mapping.ParameterAttribute(Name="CallStrike", DbType="Float")] System.Nullable callStrike,     [global::System.Data.Linq.Mapping.ParameterAttribute(Name="CallBu", DbType="Int")] System.Nullable callBu,     [global::System.Data.Linq.Mapping.ParameterAttribute(Name="CallPremium", DbType="Float")] System.Nullable callPremium,     [global::System.Data.Linq.Mapping.ParameterAttribute(Name="PutStrike", DbType="Float")] System.Nullable putStrike,     [global::System.Data.Linq.Mapping.ParameterAttribute(Name="PutBu", DbType="Int")] System.Nullable putBu,    [global::System.Data.Linq.Mapping.ParameterAttribute(Name="PutPremium", DbType="Float")] System.Nullable putPremium,    [global::System.Data.Linq.Mapping.ParameterAttribute(Name="TotalAcres", DbType="Float")] System.Nullable totalAcres,     [global::System.Data.Linq.Mapping.ParameterAttribute(Name="AvgPrice", DbType="Float")] System.Nullable avgPrice,     [global::System.Data.Linq.Mapping.ParameterAttribute(Name="PerAcreProductionCost",     DbType="Float")] System.Nullable perAcreProductionCost,    [global::System.Data.Linq.Mapping.ParameterAttribute(Name="SpringPrice", DbType="Float")] System.Nullable springPrice)   
      {
            IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), cashPrice, inputAPH, bushels, percentageCover, basicEstimate, callStrike, callBu, callPremium, putStrike, putBu, putPremium, totalAcres, avgPrice, perAcreProductionCost, springPrice);
            return ((int)(result.ReturnValue));
      }

=============================================== ==========================

我的代码将SP绑定到gridview


 var a = from risk in HRM_dc.uspCalculateRiskMatrix(CashPrice, InputAPH, Bushels, PercentageCover, BasicEstimate, CallStrike, CallBu, CallPremium,
                                                                 PutStrike, PutBu, PutPremium, TotalAcres, AvgPrice, PerAcreProductionCost, SpringPrice)
                        select risk;

                GridView gvRisk = new GridView();
                gvRisk.DataSource = a;
                gvRisk.DataBind(); 

错误: 错误2无法找到源类型“int”的查询模式的实现。找不到“选择”。

请快点帮忙 TIA

1 个答案:

答案 0 :(得分:0)

  
    

当您缺少名称空间...或源对象未实现IEnumerable时,通常会发生此类错误(未找到查询模式)。

  

检查存储过程的返回类型,它是Integer类型,它不实现IEnumerable<T>也不是集合类型。如果使用整数int[] intArray = {10, 20};数组,那么可以使用linq。

你不能像这样实现它。更多关于Gridview的DataSource属性不支持显示此类数据..

价:
Could not find an implementation of the query pattern
Linq Error "Could not find an implementation of the query pattern for source type 'System.Linq.IQueryable' Join Not Found'

编辑:根据评论: 检查此Accessing dynamically created stored procedure from LINQ,这可能是您的解决方案..