entity framework 6 - EF OData MySql Unknown column 'Project3.x' in 'where clause' -
i'm using odata v4, ef6 , mysql 5.6/5.7 below models , tables. result of application resource fine call odata/applications error when expand on roles, follows odata/applications?$expand=roles.
error: error occurred while executing command definition. see inner exception details. unknown column 'project3.applicationid' in 'where clause'
i know it's mapping, can't see what.
public class role { public int id { get; set; } public string name { get; set; } public int applicationid { get; set; } //public virtual application application { get; set; } } public class application { public int id { get; set; } public string name { get; set; } public bool isdeleted { get; set; } public virtual icollection<role> roles { get; set; } public application() { roles = new list<role>(); } } public class applicationview { public int id { get; set; } public string name { get; set; } public icollection<roleview> roles { get; set; } public applicationview() { roles = new list<roleview>(); } } public class roleview { public int id { get; set; } public string name { get; set; } public int applicationid { get; set; } } create table if not exists application ( applicationid int not null auto_increment primary key, name varchar(255) not null, isdeleted bool not null default false, createdby varchar(255) not null, createdon datetime not null, updatedby varchar(255) not null, updatedon datetime not null
) engine=innodb;
create table if not exists role ( roleid int not null auto_increment primary key, name varchar(255) not null, applicationid int not null, createdby varchar(255) not null, createdon datetime not null, updatedby varchar(255) not null, updatedon datetime not null, index app_index (applicationid), foreign key (applicationid) references application(applicationid) on delete cascade
) engine=innodb;
this odata action method.
[httpget] [odataroute("applications")] public iqueryable<applicationview> get() { var result = identityrepository.applications .include("role") .projectto<applicationview>(); return result; }
the mapping classes:
public class rolemap : entitytypeconfiguration<role> { public rolemap() { totable("role"); haskey(x => x.id); property(x => x.id).hascolumnname("roleid"); // tried with/without, no change. //hasrequired(x => x.application).withmany(x => x.roles).hasforeignkey(x => x.applicationid); } } public class applicationmap : entitytypeconfiguration<application> { public applicationmap() { totable("application"); haskey(x => x.id); property(x => x.id).hascolumnname("applicationid"); // tried with/without no change. hasmany(x => x.roles).withrequired().hasforeignkey(x => x.applicationid); } }
i tried repository both code first , database first edmx , keep getting same error.
the ef mappings seem correct. guess problem comes projectto
method. seems part of automapper queryable extensions. the documentation says (about projectto
):
note feature work, type conversions must explicitly handled in mapping. example, can not rely on tostring() override of item class inform entity framework select name column, , data type changes, such double decimal must explicitly handled well.
try replacing in query projectto
select
, or plain removing it, confirm if error comes there, or check automapper mappings.
Comments
Post a Comment