Reputation: 4291
I have created a function in database that I want to use in my Forms application in C#.
Function Execution
The above function takes one parameter and returns a value as can be seen in above png file.
I have created Entity Data Model into my Windows Form application in C#
Entity Model
I wanted to use that function into my C# code behind a button.Following is my code that is not working.
C# Code
I am pretty sure that I am NOT calling the function properly.I have tried many things but to NO avail.I was expecting that in my context object that function would be available but it was not the case.Can somebody guide me the proper way here to call View,Functions and StoredProcedures using EF Database First approach in C#?
Upvotes: 1
Views: 679
Reputation: 4000
Have you tried the code as below:
String res = DContext.Database.SqlQuery<String>("SELECT dbo.fn_getVehicleIDByIMIE(@p0)", IMEI).FirstOrDefault();
return Convert.ToInt32(res);
If it does not work let me know so I can provide another solution.
This is not tested code though...
Upvotes: 1