c# - .HasRequired Unable to work in Model -


i've been searching around answer, , unable find suitable 1 works. have 2 models 1:* relationship start with:

namespace test.models {     public class blog      {          public int id { get; set; }          public string title { get; set; }          public string bloggername { get; set; }          public virtual icollection<post> posts { get; set; }      }  }  namespace test.models {     public class post     {         public int id { get; set; }         public string title { get; set; }         public datetime datecreated { get; set; }         public string content { get; set; }         public int blogid { get; set; }         public blog blog { get; set; }     } } 

and applicationdbcontext is:

namespace test.models {      public class applicationdbcontext : identitydbcontext<applicationuser>     {         public dbset<post> post { get; set; }         public dbset<blog> blog { get; set; }         protected override void onmodelcreating(modelbuilder builder)         {              base.onmodelcreating(builder);              base.onmodelcreating(builder);              builder.entity<post>().hasrequired(p => p.blog);          }      }  } 

however, error of:

cs1061: 'entitytypebuilder' not contain definition 'hasrequiered' , no extension method 'hasrequiered' accepting first argument of type 'entitytypebuilder' found (are missing using directive or assembly reference?)

i'm new have been following various tutorials recommended use of way. appreciated. want ensure <post> part of blog. hasrequiered appears in red error though.

try one:

protected override void onmodelcreating(dbmodelbuilder modelbuilder) {      base.onmodelcreating(modelbuilder);      modelbuilder.conventions.remove<onetomanycascadedeleteconvention>();      builder.entity<post>().hasrequired(p => p.blog); } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -