c# - Fluent API - Extra column in mapping table -


i've done little fluent before appear bit stuck why i'm getting column added generated sql here.

for entities have:

public abstract class surveymodel : iequatable<surveymodel> {     [required]     public int id { get; set; }     public datetime created { get; set; }      public bool equals(surveymodel other)     {         return other.id == id;     } }  public class modulesurvey : surveymodel, iequatable<modulesurvey> {     public virtual survey survey { get; set; }     public virtual icollection<modulesurveyquestion> modulesurveyquestions { get; set; }     public string moduleid { get; set; } }  public class question : surveymodel {     [required]     public string questiontext { get; set; }     [maxlength(10)]     public string questionnumber { get; set; }     public virtual icollection<modulesurveyquestion> modulesurveyquestions { get; set; } }  public class modulesurveyquestion : surveymodel {     public virtual modulesurvey modulesurvey { get; set; }     public virtual question question { get; set; }      public virtual int modulesurveyid { get; set; }     public virtual int questionid { get; set; } } 

for mappers, have:

public class surveymap : surveybasemodelmap<survey> {     public surveymap()     {         property(survey => survey.name)             .isunicode()             .isvariablelength();          property(survey => survey.description)             .isunicode()             .isvariablelength();          totable("tblsurvey");     } }  public class modulesurveymap : surveybasemodelmap<modulesurvey> {     public modulesurveymap()     {         totable("tblmodulesurvey");          haskey(x => x.id);          // relationships         hasrequired(modulesurvey => modulesurvey.survey);     } }  public class questionmap : surveybasemodelmap<question> {     public questionmap()     {         property(question => question.questiontext)             .isunicode()             .isvariablelength();          property(question => question.questionnumber)             .isunicode()             .isvariablelength();          haskey(x => x.id);          totable("tblquestion");     } }  public class modulesurveyquestionmap : surveybasemodelmap<modulesurveyquestion> {     public modulesurveyquestionmap()     {         totable("tblmodulesurveyquestion");          // relationships         hasrequired(x => x.modulesurvey).withmany(x => x.modulesurveyquestions).hasforeignkey(x => x.modulesurveyid);         hasrequired(x => x.question).withmany(x => x.modulesurveyquestions).hasforeignkey(x => x.questionid);          // sensible property names sql column names         property(x => x.modulesurveyid).hascolumnname("modulesurvey_id");         property(x => x.questionid).hascolumnname("question_id");     } } 

until introduction of modulesurveyquestion, of worked fine.

now we've added modulesurveyquestion, following:

  1. for given survey, if try , access modulesurvey.modulesurveyquestions, retrieves modulesurveyquestion records data source.
  2. for given modulesurvey.modulesurveyquestions item's modulesurvey property, retrieves modulesurvey record data source.
  3. for given modulesurvey.modulesurveyquestions item's question property of , invalid column name 'modulesurvey_id'.; or in full:

'((system.data.entity.dynamicproxies.modulesurveyquestion_7fe909a91da6e7f79d8e677d55bb9ac81650e0f572d2a501d598422ed3e4401e)(new system.collections.generic.hashsetdebugview<uon.examportal.domain.models.surveys.modulesurveyquestion>(modulesurvey.modulesurveyquestions).items[0])).question' threw exception of type 'system.data.entitycommandexecutionexception'

in ways i'm hoping i'll post question, inflatable engineer , i'll spot error , answer own question; in case.. got ideas why ef trying access property of question object called modulesurvey_id?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -