1

Code in 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));
      }

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

My code to bind the SP with 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(); 

Error: Error 2 Could not find an implementation of the query pattern for source type 'int'. 'Select' not found.

Please help fast TIA

Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
  • Did you check what is there in 'a'? – Likurg May 10 '12 at 13:36
  • if i am using as var a = HRM_dc.uspCalculateRiskMatrix(CashPrice, InputAPH, Bushels, PercentageCover, BasicEstimate, CallStrike, CallBu, CallPremium, PutStrike, PutBu, PutPremium, TotalAcres, AvgPrice, PerAcreProductionCost, SpringPrice); a = 0 – user1387114 May 11 '12 at 13:36

1 Answers1

0

This kind of error (query pattern not found) usually happens when your lack namespace... or source object doesn't implement IEnumerable.

Check the return type of your stored procedure, It is Integer type and it does not implement IEnumerable<T> also not a collection type. If you use array of integer int[] intArray = {10, 20}; then you can use linq with it.

you can not implement it like this. More over Gridview's DataSource property does not support such type of data to display..

Ref:
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'

Edit: As per comments: check this Accessing dynamically created stored procedure from LINQ , it may be your solution..

Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
  • What should be the return type. Basically the stored procedure returns a 5X5 matrix, which i want to bind to a gridview. If i am missing something please guide – user1387114 May 10 '12 at 13:56
  • check this `return ((int)(result.ReturnValue));` in your `dbml` designer code.. that you have mentioned.. – Niranjan Singh May 10 '12 at 13:58
  • That is default when i drag and drop the SP on the DBML – user1387114 May 10 '12 at 14:02
  • use return type `ISingleResult` inherits `IEnumerable`. It is a collection that you can bind to grid after conversion. check [this](http://stackoverflow.com/questions/4433491/dbml-generates-isingleresultobject-from-my-stored-procedure-when-i-want-a-coll) – Niranjan Singh May 10 '12 at 14:03
  • sorry i am very new to linq .. please forgive for dummy questions – user1387114 May 10 '12 at 14:03
  • when i implement that it gives me erroe – user1387114 May 10 '12 at 14:10
  • in my case there is nothing like ISingleResult – user1387114 May 10 '12 at 14:12
  • ISingleResult and RiskMatric class should contain 5 `public int val1{get;set;}` like properties. and in your stored procedure return that integer array as table select statement.. follow the link specified in the above comment.. try to understand it or search on google about this.. – Niranjan Singh May 10 '12 at 14:15
  • Also the SP is not associated with any tables ... its just based on the the input parameters , it does some calculation and returns a 5X5 matrix – user1387114 May 10 '12 at 14:16
  • I am using a temp table #tblMatrix which returns a pivot table.... with dynamic headers and rows – user1387114 May 10 '12 at 14:20