c# - Invalid column name on OData result from inheritance type -
code
model
i have base , specific class
public class entidade : entitynome, iauditavel { public datetime criadoas { get; set; } public virtual usuario criadopor { get; set; } public datetime? atualizadoas { get; set; } public virtual usuario atualizadopor { get; set; } } public class empresa : entidade { public virtual icollection<pessoa> representantes { get; set; } public virtual pessoa contato { get; set; } public int contatoid { get; set; } public virtual icollection<telefone> telefones { get; set; } public virtual icollection<endereco> enderecos { get; set; } public virtual icollection<email> emails { get; set; } } public class agencia : empresa { public string identificacao { get; set; } public virtual regional regional { get; set; } public int regionalid { get; set; } public virtual icollection<pessoa> gerentes { get; set; } } ef configuration
public class entidadeconfiguracao : entitytypeconfiguration<entidade> { public entidadeconfiguracao() { property(p => p.nome).isname(true); hasrequired(p => p.criadopor).withmany().willcascadeondelete(false); totable("entidades"); } } public class empresaconfiguracao : entitytypeconfiguration<empresa> { public empresaconfiguracao() { hasmany(p => p.telefones).withmany().map(m => m.totable("empresatelefones")); hasmany(p => p.emails).withmany().map(m => m.totable("empresaemails")); hasmany(p => p.enderecos).withmany().map(m => m.totable("empresaenderecos")); hasmany(p => p.representantes).withmany().map(m => m.totable("empresarepresentantes")); hasrequired(p => p.contato).withmany().hasforeignkey(p => p.contatoid); totable("empresas"); } } public class agenciaconfiguracao : entitytypeconfiguration<agencia> { public agenciaconfiguracao() { hasrequired(p => p.regional).withmany().hasforeignkey(p => p.regionalid).willcascadeondelete(true); property(p => p.identificacao).isrequired().hasmaxlength(10); hasmany(p => p.gerentes).withmany().map(m => m.totable("agenciagerentes")); totable("agencias"); } } webapi config
modelbuilder.entityset<entidade>("entidades"); modelbuilder.entityset<empresa>("empresas"); modelbuilder.entityset<agencia>("agencias"); problem
when request /api/agencias(4471) returns:
"internalexception": { "message": "invalid column name 'regionalid'.\r\ninvalid column name 'contatoid'.", "type": "system.data.sqlclient.sqlexception", "stacktrace": " @ system.data.sqlclient.sqlconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction)\r\n @ system.data.sqlclient.sqlinternalconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction)\r\n @ system.data.sqlclient.tdsparser.throwexceptionandwarning(tdsparserstateobject stateobj, boolean callerhasconnectionlock, boolean asyncclose)\r\n @ system.data.sqlclient.tdsparser.tryrun(runbehavior runbehavior, sqlcommand cmdhandler, sqldatareader datastream, bulkcopysimpleresultset bulkcopyhandler, tdsparserstateobject stateobj, boolean& dataready)\r\n @ system.data.sqlclient.sqldatareader.tryconsumemetadata()\r\n @ system.data.sqlclient.sqldatareader.get_metadata()\r\n @ system.data.sqlclient.sqlcommand.finishexecutereader(sqldatareader ds, runbehavior runbehavior, string resetoptionsstring)\r\n @ system.data.sqlclient.sqlcommand.runexecutereadertds(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, boolean async, int32 timeout, task& task, boolean asyncwrite)\r\n @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method, taskcompletionsource`1 completion, int32 timeout, task& task, boolean asyncwrite)\r\n @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method)\r\n @ system.data.sqlclient.sqlcommand.executereader(commandbehavior behavior, string method)\r\n @ system.data.sqlclient.sqlcommand.executedbdatareader(commandbehavior behavior)\r\n @ system.data.common.dbcommand.executereader(commandbehavior behavior)\r\n @ system.data.entity.infrastructure.dbcommanddispatcher.<>c__displayclassb.<reader>b__8()\r\n @ system.data.entity.infrastructure.internaldispatcher`1.dispatch[tinterceptioncontext,tresult](func`1 operation, tinterceptioncontext interceptioncontext, action`1 executing, action`2 executed)\r\n @ system.data.entity.infrastructure.dbcommanddispatcher.reader(dbcommand command, dbcommandinterceptioncontext`1 interceptioncontext)\r\n @ system.data.entity.internal.interceptabledbcommand.executedbdatareader(commandbehavior behavior)\r\n @ system.data.common.dbcommand.executereader(commandbehavior behavior)\r\n @ system.data.entity.core.entityclient.internal.entitycommanddefinition.executestorecommands(entitycommand entitycommand, commandbehavior behavior)" } attempt
searching internet, found probable cause may misconfiguration shown in issue multiple inheritance entity framework tpc.
so tried set described:
i added map(m => m.mapinheritedproperties()); on empresaconfiguracao , agenciaconfiguracao
error:
on package manager console run add-migration test or execute app results:
the type 'empresa' cannot mapped defined because maps inherited properties types use entity splitting or form of inheritance. either choose different inheritance mapping strategy not map inherited properties, or change types in hierarchy map inherited properties , not use splitting.
Comments
Post a Comment