I have a stored procedure in SQL Server and convert it to a function in my Entity Model, now how can I convert the output of my function to a given type in C# such int,string and so on?
Example:
Testentities test=new TestEntities();
object d=test.FunctionTest("Params");
To a string:
To int:
The .NET
Convertclass can convert to a lot of different types.But a word of caution: of course you need to be certain that the target type is the right type, and even then – you need to be prepared for the fact the conversion might fail – put this in a
try...catchblock!Update: after you’ve revealed that the result is in fact a
List<object>, you need to do something like:and the same can be done with the
intvalues (just useConvert.ToInt32()in theforeachloop