Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF 6.1 Scalar-Valued Functions Database First

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.

like image 979
hncl Avatar asked Oct 15 '14 06:10

hncl


1 Answers

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.

like image 195
hncl Avatar answered Sep 28 '22 06:09

hncl