The issue is that this code gives inner exception and when it goes to the url (api/brand
) it gives this error:
The requested resource does not support http method 'GET'.
I have tried many solutions but non are working.
public class BrandController : ApiController
{
public List<Brands> DetailsGet()
{
EFDBFirstDatabaseEntities db = new EFDBFirstDatabaseEntities();
try
{
db.Configuration.LazyLoadingEnabled = false;
List<Brands> brand = db.Brands.ToList();
return brand;
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.InnerException.Message));
}
else
{
throw ex;
}
}
}
}
This is model class code:
namespace EntityPractice.Models
{
using System;
using System.Collections.Generic;
public partial class Brands
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Brands()
{
this.Products = new HashSet<Products>();
}
public long BrandID { get; set; }
public string BrandName { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Products> Products { get; set; }
}
}