0

I using Repository pattern and throw this exception.

Multiple object sets per type are not supported. The object sets 'Policyes' and 'Policies' can both contain instances of type 'VAgents.Web.Models.Policy

 public class Policy
  {
  public int Id { get; set; }
  public string Name { get; set; }
  public DateTime CreationTime { get; set; }
  public string Description { get; set; }
  }

Repository:

 public IRepository<Policy> Policyes
  {
    get
    {
       return this.GetRepository<Policy>();
    }
  }
  Interface class 
  IRepository<Policy> Policyes { get; }



public class BaseController : Controller
  {
  protected ITicketSystemData Data { get; private set; }

  protected ApplicationUser UserProfile { get; private set; }

  public BaseController(ITicketSystemData data)
  {
  this.Data = data;
  }

  protected override IAsyncResult BeginExecute(RequestContext requestContext, AsyncCallback callback, object state)
  {
  if(requestContext.HttpContext.User.Identity.IsAuthenticated)
  {
  this.UserProfile = this.Data.Users.All()
  .Where(u => u.UserName == requestContext.HttpContext.User.Identity.Name)
  .FirstOrDefault();
  }

  return base.BeginExecute(requestContext, callback, state);
  }
  }

And controller:

  public class PolicyController : BaseController
  {
  ITicketSystemData Data;
  public PolicyController(ITicketSystemData data) : base(data)
  {
  this.Data = data;
  }

  public ActionResult Index()
  {

  var getAllPolicy = this.Data.Policyes.All().Select(x=> new ListPolicyViewModel
  {
  Id = x.Id,
  Name = x.Name
  })
  .ToList();
  return View(getAllPolicy);
  }

How to fix this exception!? Thanks :)

xeso
  • 61
  • 1
  • 6
  • Your DbContext contains (either directly or through inheritance) two `DbSet` properties (one named `Policies` and one named `Policyes`). That is not allowed in Entity Framework, remove one of them. Please read [ask] and try searching before asking a new question. :) – CodeCaster Dec 01 '16 at 15:10
  • It doesn't solve your problem, but you have misspelled `Policies`. – D Stanley Dec 01 '16 at 15:10

0 Answers0