Saturday, 15 September 2012

Entity framework Invalid Column name, EF adds numer 1 to primary key -



Entity framework Invalid Column name, EF adds numer 1 to primary key -

i have 2 entityes

public partial class suscriptores { public suscriptores() { this.publicacion = new hashset<publicacion>(); } [key] public int idsuscriptor { get; set; } public string logosuscriptor { get; set; } public string identificacion { get; set; } public string nombre { get; set; } public string direccion { get; set; } public string telefono { get; set; } public string email { get; set; } public string fax { get; set; } public string home { get; set; } public virtual icollection<publicacion> publicacion { get; set; } } public partial class publicacion { public publicacion() { this.edictos = new hashset<edictos>(); } [key] public decimal idpublicacion { get; set; } public system.datetime fechapublicacion { get; set; } public string idusuario { get; set; } public system.datetime fechapublicacionhasta { get; set; } public system.datetime fechaarchivohasta { get; set; } public int idsuscriptor { get; set; } public decimal idtipopublicacion { get; set; } [foreignkey("idsuscriptor")] public virtual suscriptores suscriptores { get; set; } }

when seek run query:

public actionresult detailsvsto(string identificacion) { var susq = s in db.suscriptores s.identificacion == identificacion select s; homecoming json(susq.first(), jsonrequestbehavior.allowget); }

it throw message:

system.data.sqlclient.sqlexception: invalid column name 'suscriptores_idsuscriptor1'

trying solve problem add together fluent @ dbcontext

modelbuilder.entity<suscriptores>() .hasmany(x => x.publicacion) .withrequired(x => x.suscriptores) .map(a => a.mapkey("idsuscriptor"));

but problem persist. how can solve this.

try add together many-to-one mapping well. please utilize pure fluent api, , should remove [foreignkey] annotations.

modelbuilder.entity<publicacion>() .hasrequired(x => x.suscriptores) .withmany(x => x.publicacion);

entity-framework entity-framework-4 entity-framework-5

No comments:

Post a Comment