문제

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:

    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);
        }    
    }
}

and my Model class looks like this:

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; }
    }
}

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"

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!

도움이 되었습니까?

해결책

I have solved my problem, thanks! I had to call the udf_GetReportsByController(string controller_account) method in the controller and hand the IQueryable-Result to my view.

My Controller looks like these (Note: Beginner´s mistake)

public class ReportController : Controller { private kontrollsystemEntities db = new kontrollsystemEntities();

    //
    // GET: /Report/

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

}

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top