c# - Fluent NHibernate AutoMapping Override ignoring column name -


two tables:

create table [dbo].[error]( [errorid] [int] identity(1,1) not null, [responseid] [int] not null, <other fields>   constraint [pk_error] primary key clustered  (     [errorid] asc )  create table [dbo].[response]( [responseid] [int] identity(1,1) not null, <other fields>  constraint [pk_response] primary key clustered  (     [responseid] asc ) 

and classes

public partial class errortype {     public virtual long id { get; set; }     public virtual hr_information_type response { get; set; } <other fields> }  public class hr_information_type  {     public virtual long id { get; set; }     public virtual errortype[] errors { get; set;} <other fields> } 

i'm using auto mapping, , overriding thusly:

public class hr_information_typemap : iautomappingoverride<hr_information_type> {     public void override(automapping<hr_information_type> mapping)     {         mapping.table("response");         mapping.id(x => x.id).column("responseid");         mapping.hasmany(many => many.errors).asarray(a => a.response, x => x.column("responseid"));              } }  public class errortypemap : iautomappingoverride<errortype> {     public void override(automapping<errortype> mapping)     {         mapping.table("error");         mapping.id(id => id.id).column("errorid");         mapping.references(r => r.response, "responseid");     } } 

the problem have is, when call session.load(id), following error

"could not initialize collection: " inner exception "invalid column name 'hr_information_type_id'"

because generates sql as

select  errors0_.hr_information_type_id hr7_1_,  errors0_.errorid errorid1_,  errors0_.responseid responseid1_,  errors0_.errorid errorid26_0_, errors0_.responseid responseid26_0_  error errors0_  errors0_.hr_information_type_id=? 

i have no idea why it's looking column never said there, nor why it's looking columns twice.

what doing wrong? have similar code in other projects not using auto mapping, not correct way override?

mapping.hasmany(many => many.errors).asarray(a => a.response, part => part.column("errorid")).keycolumn("responseid").cascade.alldeleteorphan();

it needs index , key. looked @ hbm files generated ( using

.mappings(m => {     m.fluentmappings.addfromassembly(assembly).exportto(@"c:\nh.out");     m.automappings.add(am).exportto(@"c:\nh.out"); } 

)

and saw that. index part.column("errorid") piece, way indexes collection (even though it's array). has gotten me farther, not 100% sure complete answer.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -