title: Cannot implicitly convert type. An explicit conversion exists (are you missing a cast?)
body: <p>I am trying to develop a web application using ASP.Net Web API. Now after creating Product model and IProductRepository interface I'm having difficulty in showing all products. I'm getting error message</p>
  <blockquote>
  <p>Cannot implicitly convert type <code>System.Collections.Generic.IEnumerable&lt;WebApplication1.Models.Product&gt;</code> to <code>System.Collections.Generic.IEnumerable&lt;WebApplication1.Product&gt;</code>. An explicit conversion exists (are you missing a cast?)</p>
  <p>Controllers\ProductsController.cs 17  20  WebApplication1</p>
  </blockquote>
  <p>on this line of code</p>
  <p><code>return repo.GetAll();</code></p>
  <p>I don't understand what to do. If someone points out the problem and explain me what I'm doing wrong that would be very helpful.</p>
  <p><strong>ProductsController.cs</strong></p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Net.Http;
  using System.Web.Http;
  using WebApplication1.Models;
  
  namespace WebApplication1.Controllers
  {
      public class ProductsController : ApiController
      {
          static readonly IProductRepository repo = new ProductRepository();
  
          public IEnumerable&lt;Product&gt; GetAllProducts()
          {
              return repo.GetAll();
          }
      }
  }
  </code></pre>
  <p><strong>ProductRepository.cs</strong></p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Data.SqlClient;
  using System.Linq;
  using System.Web;
  
  namespace WebApplication1.Models
  {
      public class ProductRepository : IProductRepository
      {
          public string cs = System.Configuration.ConfigurationManager.ConnectionStrings[&quot;MediaSoftAppEntities&quot;].ConnectionString;
  
          public IEnumerable&lt;Product&gt; GetAll()
          {
              List&lt;Product&gt; products = new List&lt;Product&gt;();
              string sql = String.Format(&quot;Select [ProductID], [ProductName], [Price] FROM [Products]&quot;);
  
              using (SqlConnection con = new SqlConnection(cs)){
                  using (SqlCommand cmd = new SqlCommand(sql, con)){
                      con.Open();
                      SqlDataReader dr = cmd.ExecuteReader();
                      while(dr.Read()){
                          Product product = new Product();
                          product.ProductID = dr.GetInt32(0);
                          product.ProductName = dr.GetString(1);
                          product.Price = dr.GetInt32(2);
                      }
                  }
              }
              return products.ToArray();
          }
      }
  }
  </code></pre>
  <p><strong>IProductRepository.cs</strong></p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace WebApplication1.Models
  {
      public interface IProductRepository
      {
          IEnumerable&lt;Product&gt; GetAll();
      }
  }
  </code></pre>