Navigation property error when property is defined





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















My error is




A specified Include path is not valid. The EntityType 'Database.Agency' does not declare a navigation property with the name 'Sectors'.




when I am pretty sure that I have defined it properly



Agency Model



public partial class Agency
{
public Agency()
{
this.Sectors = new HashSet<Sector>();
}

public int id { get; set; }
public bool deleted { get; set; }
public string name { get; set; }
public string address1 { get; set; }
public string address2 { get; set; }
public string address3 { get; set; }
public string town { get; set; }
public int countyid { get; set; }
public string postcode { get; set; }
public string telephoneno { get; set; }
public string websiteurl { get; set; }
public string companyno { get; set; }
public string vatno { get; set; }

public virtual ICollection<Sector> Sectors { get; set; }
}


Sector Model



public partial class Sector
{
public Sector()
{
this.Agencies = new HashSet<Agency>();
}

public int id { get; set; }
public string name { get; set; }

public virtual ICollection<Agency> Agencies { get; set; }

}


It's a 'many to many' relationship.



This is where the error is occurring



[HttpGet]
public ActionResult AddOrEdit(int? id)
{
if (id == 0)
{
return View(new AgencyAll());
}
Agency agency = _db.Agencies
.Include(p => p.Sectors)
.Single(i => i.id == id);

if (agency == null)
{
return HttpNotFound();
}

ViewBag.CountyList = new SelectList(GetCountyList(), "Value", "Text");
PopulateAssignedBatData(agency);

return View(new AgencyAll {Agency = _db.Agencies.FirstOrDefault(x => x.id == id)});
}


Specifically



Agency agency = _db.Agencies
.Include(p => p.Sectors)
.Single(i => i.id == id);


Intellisence is picking up that agency has the property, I've tried defining the navigation property on the edmx in visual studio but everytime I do, it deletes all the models so I need to define this navigation property manually, I'm not sure what I'm missing here. Any help is much appreciated.










share|improve this question





























    0















    My error is




    A specified Include path is not valid. The EntityType 'Database.Agency' does not declare a navigation property with the name 'Sectors'.




    when I am pretty sure that I have defined it properly



    Agency Model



    public partial class Agency
    {
    public Agency()
    {
    this.Sectors = new HashSet<Sector>();
    }

    public int id { get; set; }
    public bool deleted { get; set; }
    public string name { get; set; }
    public string address1 { get; set; }
    public string address2 { get; set; }
    public string address3 { get; set; }
    public string town { get; set; }
    public int countyid { get; set; }
    public string postcode { get; set; }
    public string telephoneno { get; set; }
    public string websiteurl { get; set; }
    public string companyno { get; set; }
    public string vatno { get; set; }

    public virtual ICollection<Sector> Sectors { get; set; }
    }


    Sector Model



    public partial class Sector
    {
    public Sector()
    {
    this.Agencies = new HashSet<Agency>();
    }

    public int id { get; set; }
    public string name { get; set; }

    public virtual ICollection<Agency> Agencies { get; set; }

    }


    It's a 'many to many' relationship.



    This is where the error is occurring



    [HttpGet]
    public ActionResult AddOrEdit(int? id)
    {
    if (id == 0)
    {
    return View(new AgencyAll());
    }
    Agency agency = _db.Agencies
    .Include(p => p.Sectors)
    .Single(i => i.id == id);

    if (agency == null)
    {
    return HttpNotFound();
    }

    ViewBag.CountyList = new SelectList(GetCountyList(), "Value", "Text");
    PopulateAssignedBatData(agency);

    return View(new AgencyAll {Agency = _db.Agencies.FirstOrDefault(x => x.id == id)});
    }


    Specifically



    Agency agency = _db.Agencies
    .Include(p => p.Sectors)
    .Single(i => i.id == id);


    Intellisence is picking up that agency has the property, I've tried defining the navigation property on the edmx in visual studio but everytime I do, it deletes all the models so I need to define this navigation property manually, I'm not sure what I'm missing here. Any help is much appreciated.










    share|improve this question

























      0












      0








      0








      My error is




      A specified Include path is not valid. The EntityType 'Database.Agency' does not declare a navigation property with the name 'Sectors'.




      when I am pretty sure that I have defined it properly



      Agency Model



      public partial class Agency
      {
      public Agency()
      {
      this.Sectors = new HashSet<Sector>();
      }

      public int id { get; set; }
      public bool deleted { get; set; }
      public string name { get; set; }
      public string address1 { get; set; }
      public string address2 { get; set; }
      public string address3 { get; set; }
      public string town { get; set; }
      public int countyid { get; set; }
      public string postcode { get; set; }
      public string telephoneno { get; set; }
      public string websiteurl { get; set; }
      public string companyno { get; set; }
      public string vatno { get; set; }

      public virtual ICollection<Sector> Sectors { get; set; }
      }


      Sector Model



      public partial class Sector
      {
      public Sector()
      {
      this.Agencies = new HashSet<Agency>();
      }

      public int id { get; set; }
      public string name { get; set; }

      public virtual ICollection<Agency> Agencies { get; set; }

      }


      It's a 'many to many' relationship.



      This is where the error is occurring



      [HttpGet]
      public ActionResult AddOrEdit(int? id)
      {
      if (id == 0)
      {
      return View(new AgencyAll());
      }
      Agency agency = _db.Agencies
      .Include(p => p.Sectors)
      .Single(i => i.id == id);

      if (agency == null)
      {
      return HttpNotFound();
      }

      ViewBag.CountyList = new SelectList(GetCountyList(), "Value", "Text");
      PopulateAssignedBatData(agency);

      return View(new AgencyAll {Agency = _db.Agencies.FirstOrDefault(x => x.id == id)});
      }


      Specifically



      Agency agency = _db.Agencies
      .Include(p => p.Sectors)
      .Single(i => i.id == id);


      Intellisence is picking up that agency has the property, I've tried defining the navigation property on the edmx in visual studio but everytime I do, it deletes all the models so I need to define this navigation property manually, I'm not sure what I'm missing here. Any help is much appreciated.










      share|improve this question














      My error is




      A specified Include path is not valid. The EntityType 'Database.Agency' does not declare a navigation property with the name 'Sectors'.




      when I am pretty sure that I have defined it properly



      Agency Model



      public partial class Agency
      {
      public Agency()
      {
      this.Sectors = new HashSet<Sector>();
      }

      public int id { get; set; }
      public bool deleted { get; set; }
      public string name { get; set; }
      public string address1 { get; set; }
      public string address2 { get; set; }
      public string address3 { get; set; }
      public string town { get; set; }
      public int countyid { get; set; }
      public string postcode { get; set; }
      public string telephoneno { get; set; }
      public string websiteurl { get; set; }
      public string companyno { get; set; }
      public string vatno { get; set; }

      public virtual ICollection<Sector> Sectors { get; set; }
      }


      Sector Model



      public partial class Sector
      {
      public Sector()
      {
      this.Agencies = new HashSet<Agency>();
      }

      public int id { get; set; }
      public string name { get; set; }

      public virtual ICollection<Agency> Agencies { get; set; }

      }


      It's a 'many to many' relationship.



      This is where the error is occurring



      [HttpGet]
      public ActionResult AddOrEdit(int? id)
      {
      if (id == 0)
      {
      return View(new AgencyAll());
      }
      Agency agency = _db.Agencies
      .Include(p => p.Sectors)
      .Single(i => i.id == id);

      if (agency == null)
      {
      return HttpNotFound();
      }

      ViewBag.CountyList = new SelectList(GetCountyList(), "Value", "Text");
      PopulateAssignedBatData(agency);

      return View(new AgencyAll {Agency = _db.Agencies.FirstOrDefault(x => x.id == id)});
      }


      Specifically



      Agency agency = _db.Agencies
      .Include(p => p.Sectors)
      .Single(i => i.id == id);


      Intellisence is picking up that agency has the property, I've tried defining the navigation property on the edmx in visual studio but everytime I do, it deletes all the models so I need to define this navigation property manually, I'm not sure what I'm missing here. Any help is much appreciated.







      c# asp.net-mvc navigation-properties






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 13:52









      Kieran DeeKieran Dee

      598




      598
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339202%2fnavigation-property-error-when-property-is-defined%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339202%2fnavigation-property-error-when-property-is-defined%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          List item for chat from Array inside array React Native

          Thiostrepton

          Caerphilly