EntityFramework-Reverse-POCO-Code-First-Generator icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard

When executing a command, parameters must be exclusively database parameters or values.

Open SABARISHV06 opened this issue 9 years ago • 8 comments

I was trying to call the stored procedure generated from POCO. I have cross checked many times but all the parameters in the SP and code are same. I am spending many time on this. The generated method is returning only int (public int CspGetHomePage(string chrCode, int? intRestId, System.DateTime? sdtmWeek, string chrCriteria)) but I want it in a return model. Hence I customized to return it as modal method (public System.Collections.Generic.List GetForecastForHomePage(string chrCode, int? intRestId, System.DateTime? sdtmWeek, string chrCriteria,out int procResult)) Shall we do customize the auto-generated code or not ? Please suggest. @sjh37

SABARISHV06 avatar Oct 09 '17 10:10 SABARISHV06

Does your customised code work? Can you show me the stored procedure?

sjh37 avatar Oct 09 '17 12:10 sjh37

Yes my customized code builds successfully. I can able to call the CspGetHomePage method and it execute successfully. But when I call the customized code its throwing me error. For your reference i have attached the Stored Procedure. @sjh37

SABARISHV06 avatar Oct 09 '17 12:10 SABARISHV06

I hope this issue is already marked. https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/issues/316 #316 @sjh37 am I issue is related to that?

SABARISHV06 avatar Oct 09 '17 13:10 SABARISHV06

Yes, it could be related to #316.

If you run the following in SSMS, with suitable parameters, do you get your results ok without an error?

DECLARE @chrCorpCode CHAR(4) = 'aaaa';
DECLARE @intRestaurantID INTEGER = 1;
DECLARE @sdtmRestaurantWeek SMALLDATETIME = GETDATE() - 1;
DECLARE @chrBusinessCriteria CHAR(3) = 'bbb';
exec [dbo].[csp_GET_ForecastForHomePage] @chrCorpCode, @intRestaurantID, @sdtmRestaurantWeek, @chrBusinessCriteria;

sjh37 avatar Oct 09 '17 14:10 sjh37

Yes I can see my results. @sjh37 Now is it possible to get the result from the code?

SABARISHV06 avatar Oct 09 '17 15:10 SABARISHV06

No not yet. I'll have to test with another variation of your stored procedure as I don't have your tables. For now, keep using your customised code.

sjh37 avatar Oct 09 '17 16:10 sjh37

Actually customized POCO generated code is throwing me the Error. (When executing a command, parameters must be exclusively database parameters or values.) So now i was trying to make LINQ statement. Kindly let me know if any other approaches comes.

SABARISHV06 avatar Oct 09 '17 17:10 SABARISHV06

That EF error comes from mixing SqlParameter objects with raw values. The underlying problem, a return model the database cannot describe, is handled in v4 by defining the model yourself in Settings.ReadStoredProcReturnObjectCompleted; see Stored Procedure Return Model Errors. Closing.

sjh37 avatar Sep 24 '26 10:09 sjh37