1

I am trying to execute stored procedure using Massive micro-orm.

var tbl = new DynamicModel("Conn", tableName: "User", primaryKeyField: "UserID");
var result = tbl.Query("EXEC User_INSERT @0,@1,@2,@3", "7843bf9d-9cb8-495b-aaa5-785ac74b82a5", "7FBDDG58-B08E-4723-9477-C9E791CDF36E", "Admin", "11/20/2012");

While debugging it does not even go to Massive library. I also tried like...

var result = tbl.Query(@"EXEC ...);

and also

var result = tbl.Query("User_INSERT @0,...);

Nothing seems to be working. With same handle SELECT query works, but not the stored procedure. If I create a break point in the statement and load the same in "Quick watch" and expand dynamic result, it fires up stored procedure.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Rajul
  • 135
  • 10
  • How come you are not showing the Select Query.. ? – MethodMan Nov 20 '12 at 22:55
  • Something like var result=tbl.Query("Select * from User"); works (This is I mean when I mentioned SELECT query works). So connection is not an issue. But by passing stored procedure name it does not work. – Rajul Nov 21 '12 at 01:39

2 Answers2

3

DynamicModel.Query returns an IEnumerable therefore the query (or stored procedure in this case) is never executed in SQL until the IEnumerable needs to be evaluated in your C# code.

You can force the evaluation of the IEnumerable by simply adding .ToList() to the end of your .Query() call:

var tbl = new DynamicModel("Conn", tableName: "User", primaryKeyField: "UserID");
var result = tbl.Query("EXEC User_INSERT @0,@1,@2,@3", "7843bf9d-9cb8-495b-aaa5-785ac74b82a5", "7FBDDG58-B08E-4723-9477-C9E791CDF36E", "Admin", "11/20/2012").ToList();
dmazz55
  • 61
  • 6
0

This is just a rough guess since I don't understand what your error message is and require more information but you can't pass your GUID's as a string (unless it is accepting it as a string type?). Perhaps try

var result = tbl.Query("EXEC User_INSERT @0,@1,@2,@3", 
New Guid("7843bf9d-9cb8-495b-aaa5-785ac74b82a5"), 
New Guid("7FBDDG58-   B08E-4723-9477-C9E791CDF36E"), "Admin", "11/20/2012");
MVCKarl
  • 1,283
  • 9
  • 7
  • stored procedure does accept NVARCHAR that is the reason I passed it as a string. When I debug the above statement, it does not do anything. It just skips to the next statement without executing the stored procedure. In fact parameter values comes from dynamic object like objUser.AddressID, objUser.RegionID, objUser.UserName, objUser.CreateDate. But for testing purpose I hardcoded the values in the query. I am using latest stable build from Massive. Thanks. – Rajul Nov 21 '12 at 02:17