title: How to expose database view in WebAPI Odata V4
body: <p>I have imported view from database to edmx and added [Key] attribute to model POCO class:</p>
  
  <p>namespace TFOMS.Domain.Model</p>
  
  <pre><code>{
      using System;
      using System.Collections.Generic;
      using System.ComponentModel.DataAnnotations;
  
      public partial class vw_Tariffs_PR
      {
  
          public int TariffId { get; set; }
          public string MCOD { get; set; }
          public string OrgName { get; set; }
          public Nullable&lt;int&gt; IDPR { get; set; }
          public string PRNAME { get; set; }
          public Nullable&lt;int&gt; IDSP { get; set; }
          public string SPNAME { get; set; }
          public Nullable&lt;byte&gt; isChild { get; set; }
          public decimal tariff { get; set; }
          public System.DateTime DATEBEG { get; set; }
          public Nullable&lt;System.DateTime&gt; DATEEND { get; set; }
      }
  }
  </code></pre>
  
  <p>I need to expose this view in webapi odata controller, but when I add following code to WebApiConfig.cs</p>
  
  <pre><code> public static class WebApiConfig
      {
          public static void Register(HttpConfiguration config)
          {
              // Web API configuration and services
              ODataModelBuilder builder = new ODataConventionModelBuilder();
              builder.EntitySet&lt;vw_Tariffs_PR&gt;("vw_Tariffs_PR");
              var model = builder.GetEdmModel();
              config.MapODataServiceRoute(
              routeName: "ODataRoute",
              routePrefix: "odata",
              model: model);
  
              // Web API routes
              config.MapHttpAttributeRoutes();
  
              config.Routes.MapHttpRoute(
                  name: "DefaultApi",
                  routeTemplate: "api/{controller}/{id}",
                  defaults: new { id = RouteParameter.Optional }
              );
          }
      }
  </code></pre>
  
  <p>But when I start application I receive error: 
  {"The entity 'vw_Tariffs_PR' does not have a key defined."} 
  in
  var model = builder.GetEdmModel();</p>
  
  <p>After I add [Key] attribute to TariffId property I receive error in:</p>
  
  <pre><code>public class Global : HttpApplication
  {
      void Application_Start(object sender, EventArgs e)
      {
          // Код, выполняемый при запуске приложения
          AreaRegistration.RegisterAllAreas();
          **GlobalConfiguration.Configure(WebApiConfig.Register);**
          RouteConfig.RegisterRoutes(RouteTable.Routes);            
      }
  }
  </code></pre>
  
  <p>In line GlobalConfiguration.Configure(WebApiConfig.Register);
  {"ValueFactory try to get acces to property Value of this instance."}</p>
  
  <p>Can anybody explain how to expose view in odata controller, what I do wrong?</p>