title: Creating a MVC4-Controller using Entity Framework
body: <p>Hey Guys I hava a question. I know questions like this are asked often, but I worked on a solution for several hours and read many answers but I couldnt find the right one. I am doing an application using ASP.NET MVC 4 Razor. I´m rather new to this system. I created a .edmx Data Model using Entity Framework 5 (Database-First Approach). This is how my auto-generated Context class looks like:</p>
  
  <pre><code>    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&lt;udf_GetReportsByController_Result&gt; 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&lt;udf_GetReportsByController_Result&gt;("[kontrollsystemEntities].[udf_GetReportsByController](@controller_account)", controller_accountParameter);
          }    
      }
  }
  </code></pre>
  
  <p>and my Model class looks like this:</p>
  
  <pre><code>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; }
      }
  }
  </code></pre>
  
  <p>When I now click on "Add Controller" and select my classes, I get the error message:
  "Unable to retrieve Metadata for KSM3.Models.udf_GetReportsByController_Result.cs"</p>
  
  <p>Note: I am using Entity Framework to retrieve information from a user-defined function, not from a table! If I try the same procedure with a table, it works!
  What do I have to prepare or change in order to make this work? 
  Thank you for all answers!</p>