My application is c# MVC5, using EF 6.1. Imported tables and functions using Database First. I can see the function in model (emdx) browser listed under DALModel.Store / Stored Procedures / Functions (grayed out).
I am trying to use the function using the following:
using (var ctx = new DALEntities())
{
int? result = ctx.fn_TotalClient(MemberRepository.AllowedCId, fromDate, toDate);
return (result != null ? result.Value : 0);
}
I get can't resolve fn_TotalClient
Would appreciate your suggestions.
Apparently I could not use Scalar-Valued Function directly into my model; I found a solution in this blog http://programmaticponderings.wordpress.com/2012/11/22/first-impressions-of-database-first-development-with-entity-framework-5-in-visual-studio-2012/.
However, I used a different approach by redeveloping the function as a Table-Valued Function, then used FirstOrDefault() to get the result value.
Hope this could help someone facing the same issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With