EF 6.1标量值函数数据库优先

hnc*_*ncl 7 c# asp.net-mvc entity-framework sql-function

我的应用程序是c#MVC5,使用EF 6.1.使用Database First导入的表和函数.我可以在DALModel.Store/Stored Procedures/Functions(灰显)下列出的模型(emdx)浏览器中看到该功能.

我试图使用以下功能:

using (var ctx = new DALEntities())
{
    int? result = ctx.fn_TotalClient(MemberRepository.AllowedCId, fromDate, toDate);
    return (result != null ? result.Value : 0);
}
Run Code Online (Sandbox Code Playgroud)

我得到无法解析fn_TotalClient

非常感谢您的建议.

hnc*_*ncl 9

显然我不能直接在我的模型中使用标量值函数; 我在这个博客中找到了一个解决方案http://programmaticponderings.wordpress.com/2012/11/22/first-impressions-of-database-first-development-with-entity-framework-5-in-visual-studio-2012 /.

但是,我使用不同的方法将函数重新开发为表值函数,然后使用FirstOrDefault()来获取结果值.

希望这可以帮助面临同样问题的人.