verdie-g / StoredProcedureEFCore

Entity Framework Core extension to execute stored procedures
MIT License
192 stars 44 forks source link

Wrong ParameterDirection set in AddParam routine #36

Closed PetrPospisil closed 4 years ago

PetrPospisil commented 4 years ago

This line must set ParameterDirection.InputOutput rather then ParameterDirection.Output, because it is a in&out routine.

https://github.com/verdie-g/StoredProcedureEFCore/blob/f883a444eb808253efdd6e841826f9bc0d773786/StoredProcedureEFCore/StoredProcBuilder.cs#L44

As a workaround we currently use this piece of code: // fix missing input output parameter direction var type = builder.GetType().Assembly.GetTypes().Where(t => t.Name == "StoredProcBuilder").First(); var field = type.GetField("_cmd", BindingFlags.NonPublic | BindingFlags.Instance); var sqlCommand = field.GetValue(builder) as SqlCommand; sqlCommand.Parameters[parameterName].Direction = ParameterDirection.InputOutput;

Thx.

ornatwork commented 4 years ago

Hi @verdie-g is there a way to pass input-output with a value ? I want to pass value to a sproc and get output from the sproc using the same parameter. I see you have OutputParam class but it is internal, therefor I can not use it.

If possible can you share example code ?

verdie-g commented 4 years ago

Hello @ornatwork, you should use this overload https://github.com/verdie-g/StoredProcedureEFCore/blob/6171d12503cb1be10b2d842b2dec2cba8cec2304/StoredProcedureEFCore/IStoredProcBuilder.cs#L28

ornatwork commented 4 years ago

@verdie-g Works as expected, thanks for the great library !