Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用实体框架创建MVC4控制器_C#_Entity Framework_Asp.net Mvc 4_Scaffolding_Database First - Fatal编程技术网

C# 使用实体框架创建MVC4控制器

C# 使用实体框架创建MVC4控制器,c#,entity-framework,asp.net-mvc-4,scaffolding,database-first,C#,Entity Framework,Asp.net Mvc 4,Scaffolding,Database First,嘿,伙计们,我有个问题。我知道这样的问题经常被问到,但我花了几个小时研究一个解决方案,读了很多答案,但我找不到正确的答案。我正在用ASP.NETMVC4Razor做一个应用程序。我对这个系统相当陌生。我使用EntityFramework5(数据库优先方法)创建了一个.edmx数据模型。这是我的自动生成上下文类的外观: namespace KSM3.Models { using System; using System.Data.Entity; using Syst

嘿,伙计们,我有个问题。我知道这样的问题经常被问到,但我花了几个小时研究一个解决方案,读了很多答案,但我找不到正确的答案。我正在用ASP.NETMVC4Razor做一个应用程序。我对这个系统相当陌生。我使用EntityFramework5(数据库优先方法)创建了一个.edmx数据模型。这是我的自动生成上下文类的外观:

    namespace KSM3.Models
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
    using System.Data.Objects;
    using System.Data.Objects.DataClasses;
    using System.Linq;

    public partial class kontrollsystemEntities : DbContext
    {
        public kontrollsystemEntities()
            : base("name=kontrollsystemEntities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }


        [EdmFunction("kontrollsystemEntities", "udf_GetReportsByController")]
        public virtual IQueryable<udf_GetReportsByController_Result> udf_GetReportsByController(string controller_account)
        {
            var controller_accountParameter = controller_account != null ?
                new ObjectParameter("controller_account", controller_account) :
                new ObjectParameter("controller_account", typeof(string));

            return ((IObjectContextAdapter)this).ObjectContext.CreateQuery<udf_GetReportsByController_Result>("[kontrollsystemEntities].[udf_GetReportsByController](@controller_account)", controller_accountParameter);
        }    
    }
}
当我现在单击“添加控制器”并选择我的类时,我会收到错误消息: “无法检索KSM3.Models.udf_GetReportsByController_Result.cs的元数据”

注意:我使用实体框架从用户定义的函数中检索信息,而不是从表中!如果我对一张桌子尝试同样的程序,它会起作用! 为了使这项工作顺利进行,我必须准备或改变什么?
谢谢你的回答

我已经解决了我的问题,谢谢! 我必须在控制器中调用udf_GetReportsByController(字符串控制器_帐户)方法,并将IQueryable结果交给我的视图

我的控制器看起来像这样(注:初学者的错误)

公共类ReportController:控制器 { 私有kontrollsystemEntities db=新的kontrollsystemEntities()

//
//获取/报告/
公共行动结果索引()
{
IQueryable result=db.udf_GetReportsByController(User.Identity.Name);
返回视图(result.ToList());
}
}

}

udf_GetReportsByController是存储过程吗?不是返回表的用户定义函数。
namespace KSM3.Models
{
    using System;

    public partial class udf_GetReportsByController_Result
    {
        public int ID { get; set; }
        public string ProviderID { get; set; }
        public int VertragID { get; set; }
        public System.DateTime Leistungszeitraum_von { get; set; }
        public System.DateTime Leistungszeitraum_bis { get; set; }
        public string ReportklasseID { get; set; }
        public int Version { get; set; }
        public string Status { get; set; }
    }
}
    //
    // GET: /Report/

    public ActionResult Index()
    {
        IQueryable<udf_GetReportsByController_Result> result = db.udf_GetReportsByController(User.Identity.Name);
        return View(result.ToList());
    }
}