【问题标题】:Why can I see stored procs and scalar functions in Entity Framework data model but not my controller?为什么我可以在实体框架数据模型中看到存储的过程和标量函数,但看不到我的控制器?
【发布时间】:2014-02-04 13:20:04
【问题描述】:

我在我的 MVC 3 解决方案中创建了一个新项目,其中将数据库优先的实体框架模型映射到 SQL Server 2008 数据库。我在模型中包含了所有表、视图、存储过程等。我可以在查看数据模型时看到我想要使用的标量函数,但是当我尝试在控制器中使用 proc 或函数名称作为对象时,Intellisense 看不到它并且应用程序出错。我还需要做什么才能在控制器中使用存储过程和函数吗?

 using System;
 using System.Collections.Generic;
 using System.Data;
 using System.Data.Entity;
 using System.Linq;
 using System.Web;
 using System.Web.Mvc;
 using Newtonsoft.Json;
 using System.Web.Security;
 using System.Data.Objects.SqlClient;
 using JobBoard.Models;
 using JobBoardDAL.Models;

 namespace JobBoard.Controllers
 {
     public class AccountController : Controller       
     {


    private DataModel db = new DataModel();

    public ActionResult Authenticate() {
        .....
        var x = db.IsUser(somevariable); // <---- Problem is here
    {

    }

}

}

【问题讨论】:

    标签: c# sql-server asp.net-mvc entity-framework visual-studio-2012


    【解决方案1】:

    您需要将 SP 和函数添加到 edmx 模型中,并将它们映射到复杂类型。

    here

    【讨论】:

    • 它对我不起作用。首先,我尝试使用标量函数创建函数导入。当这不起作用时,我做了一些进一步的研究,似乎 EF 不直接支持标量函数,所以我用我的函数代码创建了一个存储过程,然后重新生成了模型。我的存储过程现在显示为函数导入,但我仍然无法从控制器调用它。我还使用相同的存储过程创建了另一个具有不同名称的函数导入。结果相同。我错过了一步吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    • 2020-11-22
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多