我的应用程序是 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);
}
我无法解析 fn_TotalClient
非常感谢您的建议。
最佳答案
显然我不能在我的模型中直接使用标量值函数;我在这个博客中找到了解决方案 http://programmaticponderings.wordpress.com/2012/11/22/first-impressions-of-database-first-development-with-entity-framework-5-in-visual-studio-2012/ .
但是,我使用了一种不同的方法,将函数重新开发为表值函数,然后使用 FirstOrDefault() 来获取结果值。
希望这可以帮助面临同样问题的人。
关于c# - EF 6.1 标量值函数数据库优先,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26375822/