From: Joseph M. <jo...@jm...> - 2013-01-09 22:19:25
|
I have a stored procedure in my database that returns a scalar value (a double). I am trying to figure out how to get the results via ExecuteStoreQuery, using Entity Framework. Here is my c# code: var db = new MyEntities(); var oc = ((IObjectContextAdapter)db).ObjectContext; string myquery = "execute procedure PREDICT_COST_1 ('12345',1)"; var result = oc.ExecuteStoreQuery<double>(myquery); double thecost = result.First<double>(); If I set a breakpoint before the last line and inspect the result variable, it is an empty ObjectResult. So, the last line raises an exception when I call First() because it is empty. I know that the stored procedure should be returning a value, because if I execute it directly against the database with the same parameters, it returns the correct value. Here's the source for my stored procedure: create procedure PREDICT_COST_1 (BARCODE VarChar(25), STOREID INTEGER) returns (THE_COST Double Precision) as DECLARE VARIABLE TEMP_COST Double Precision; BEGIN select first 1 itemcost from orderitems A inner join orders B on A.orderid = B.orderid where A.itembarcode = :BARCODE and A.itemqtyordered > A.itemqtyreceived and A.itemcost > 0 order by B.orderdate desc into :TEMP_COST; if (TEMP_COST is null) then BEGIN select first 1 A.vpcost from vendorproducts A inner join products B on A.VPUPC = B.PRODBARCODE and A.VPVENDOR = B.PRODSOURCE where B.prodbarcode = :BARCODE and A.STOREID = :STOREID and A.vpcost > 0 into :TEMP_COST; if (TEMP_COST is null) then BEGIN select first 1 vpcost from vendorproducts where vpupc = :BARCODE and STOREID = :STOREID and vpcost > 0 into :TEMP_COST; END END THE_COST = TEMP_COST; END What am I doing wrong? -Joe |
From: Jiri C. <di...@ci...> - 2013-01-10 10:39:18
|
The procedure needs to be selectable. -- Jiri {x2} Cincura (x2develop.com founder) http://blog.cincura.net/ | http://www.ID3renamer.com |
From: Joseph M. <jo...@jm...> - 2013-01-10 17:24:42
|
Ok, so you're saying that without changing the SP, there's no way to retrieve the result via ExecuteStoreQuery? If that's the case, do you know of any other method to run the query and retrieve the scalar result from .NET? By the way, do you think this could also be the issue with me being unable to import the SP's into Entity Framework (see other thread)? -Joe On Thu, Jan 10, 2013 at 2:39 AM, Jiri Cincura <di...@ci...> wrote: > The procedure needs to be selectable. > > > -- > Jiri {x2} Cincura (x2develop.com founder) > http://blog.cincura.net/ | http://www.ID3renamer.com > > > ------------------------------------------------------------------------------ > Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, > MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current > with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft > MVPs and experts. ON SALE this month only -- learn more at: > http://p.sf.net/sfu/learnmore_122712 > _______________________________________________ > Firebird-net-provider mailing list > Fir...@li... > https://lists.sourceforge.net/lists/listinfo/firebird-net-provider > |
From: Jiri C. <di...@ci...> - 2013-01-11 05:43:53
|
On Thu, Jan 10, 2013 at 6:24 PM, Joseph Martinez <jo...@jm...> wrote: > Ok, so you're saying that without changing the SP, there's no way to > retrieve the result via ExecuteStoreQuery? If that's the case, do you know > of any other method to run the query and retrieve the scalar result from > .NET? This is not a scalar result. It's result it output parameter. > By the way, do you think this could also be the issue with me being unable > to import the SP's into Entity Framework (see other thread)? Yes. -- Jiri {x2} Cincura (x2develop.com founder) http://blog.cincura.net/ | http://www.ID3renamer.com |
From: Joseph M. <jo...@jm...> - 2013-01-11 07:00:45
|
Ok, thanks. Is there any way possible in .NET to call a stored procedure and retrieve the output parameter? -Joe On Thu, Jan 10, 2013 at 9:43 PM, Jiri Cincura <di...@ci...> wrote: > On Thu, Jan 10, 2013 at 6:24 PM, Joseph Martinez <jo...@jm...> > wrote: > > Ok, so you're saying that without changing the SP, there's no way to > > retrieve the result via ExecuteStoreQuery? If that's the case, do you > know > > of any other method to run the query and retrieve the scalar result from > > .NET? > > This is not a scalar result. It's result it output parameter. > > > By the way, do you think this could also be the issue with me being > unable > > to import the SP's into Entity Framework (see other thread)? > > Yes. > > -- > Jiri {x2} Cincura (x2develop.com founder) > http://blog.cincura.net/ | http://www.ID3renamer.com > > > ------------------------------------------------------------------------------ > Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and > much more. Get web development skills now with LearnDevNow - > 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts. > SALE $99.99 this month only -- learn more at: > http://p.sf.net/sfu/learnmore_122812 > _______________________________________________ > Firebird-net-provider mailing list > Fir...@li... > https://lists.sourceforge.net/lists/listinfo/firebird-net-provider > |
From: Jiri C. <di...@ci...> - 2013-01-11 07:32:59
|
On Fri, Jan 11, 2013 at 8:00 AM, Joseph Martinez <jo...@jm...> wrote: > Is there any way possible in .NET to call a stored procedure and retrieve > the output parameter? Sure. Just use FbCommand. -- Jiri {x2} Cincura (x2develop.com founder) http://blog.cincura.net/ | http://www.ID3renamer.com |