不支持每种类型的多个对象集。对象设置'政策'和政策'可以包含类型'策略

时间:2016-12-01 15:06:36

标签: c# asp.net .net asp.net-mvc

我使用Repository模式并抛出此异常。

  

不支持每种类型的多个对象集。对象设置'政策'和政策'都可以包含类型的实例   ' 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; }
  }

存储库:

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

和控制器:

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

如何修复此异常!? 谢谢:)

0 个答案:

没有答案