@@ -467,21 +467,21 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common) {
467467 if ( trycol != null && trycol . CsType . NullableTypeOrThis ( ) != trytb . Primarys [ a ] . CsType ) {
468468 nvref . Exception = new Exception ( $ "【OneToMany】导航属性 { trytbTypeName } .{ pnv . Name } 解析错误,{ trytb . CsName } .{ trytb . Primarys [ a ] . CsName } 和 { tbref . CsName } .{ trycol . CsName } 类型不一致") ;
469469 trytb . AddOrUpdateTableRef ( pnv . Name , nvref ) ;
470- if ( isLazy ) throw nvref . Exception ;
470+ // if (isLazy) throw nvref.Exception;
471471 continue ;
472472 }
473473 if ( trycol == null ) {
474474 nvref . Exception = new Exception ( $ "【OneToMany】导航属性 { trytbTypeName } .{ pnv . Name } 在 { tbref . CsName } 中没有找到对应的字段,如:{ findtrytb } { findtrytbPkCsName } 、{ findtrytb } _{ findtrytbPkCsName } " + ( refprop == null ? "" : $ "、{ refprop . Name } { findtrytbPkCsName } 、{ refprop . Name } _{ findtrytbPkCsName } ") ) ;
475475 trytb . AddOrUpdateTableRef ( pnv . Name , nvref ) ;
476- if ( isLazy ) throw nvref . Exception ;
476+ // if (isLazy) throw nvref.Exception;
477477 continue ;
478478 }
479479 }
480480
481481 nvref . Columns . Add ( trytb . Primarys [ a ] ) ;
482482 nvref . RefColumns . Add ( trycol ) ;
483483
484- if ( isLazy ) {
484+ if ( isLazy && nvref . Exception == null ) {
485485 if ( a > 0 ) lmbdWhere . Append ( " && " ) ;
486486 lmbdWhere . Append ( "a." ) . Append ( trycol . CsName ) . Append ( " == this." ) . Append ( trytb . Primarys [ a ] . CsName ) ;
487487
@@ -506,13 +506,19 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common) {
506506 . Append ( " public override " ) . Append ( propTypeName ) . Append ( " " ) . Append ( pnv . Name ) . AppendLine ( " {" ) ;
507507 if ( vp . Item2 ) { //get 重写
508508 cscode . Append ( " get {\r \n " )
509- . Append ( " if (base." ) . Append ( pnv . Name ) . Append ( " == null && __lazy__" ) . Append ( pnv . Name ) . AppendLine ( " == false) {" )
510- . Append ( " base." ) . Append ( pnv . Name ) . Append ( " = __fsql_orm__.Select<" ) . Append ( propElementType . IsNested ? $ "{ propElementType . DeclaringType . Namespace } .{ propElementType . DeclaringType . Name } .{ propElementType . Name } " : $ "{ propElementType . Namespace } .{ propElementType . Name } ") . Append ( ">().Where(a => " ) . Append ( lmbdWhere . ToString ( ) ) . AppendLine ( ").ToList();" ) ;
511- if ( refprop != null ) {
512- cscode . Append ( " foreach (var loc1 in base." ) . Append ( pnv . Name ) . AppendLine ( ")" )
513- . Append ( " loc1." ) . Append ( refprop . Name ) . AppendLine ( " = this;" ) ;
514- }
515- cscode . Append ( " __lazy__" ) . Append ( pnv . Name ) . AppendLine ( " = true;" )
509+ . Append ( " if (base." ) . Append ( pnv . Name ) . Append ( " == null && __lazy__" ) . Append ( pnv . Name ) . AppendLine ( " == false) {" ) ;
510+
511+ if ( nvref . Exception == null ) {
512+ cscode . Append ( " base." ) . Append ( pnv . Name ) . Append ( " = __fsql_orm__.Select<" ) . Append ( propElementType . IsNested ? $ "{ propElementType . DeclaringType . Namespace } .{ propElementType . DeclaringType . Name } .{ propElementType . Name } " : $ "{ propElementType . Namespace } .{ propElementType . Name } ") . Append ( ">().Where(a => " ) . Append ( lmbdWhere . ToString ( ) ) . AppendLine ( ").ToList();" ) ;
513+ if ( refprop != null ) {
514+ cscode . Append ( " foreach (var loc1 in base." ) . Append ( pnv . Name ) . AppendLine ( ")" )
515+ . Append ( " loc1." ) . Append ( refprop . Name ) . AppendLine ( " = this;" )
516+ . Append ( " __lazy__" ) . Append ( pnv . Name ) . AppendLine ( " = true;" ) ;
517+ }
518+ } else
519+ cscode . Append ( " throw new Exception(\" " ) . Append ( nvref . Exception . Message . Replace ( "\r \n " , "\\ r\\ n" ) . Replace ( "\" " , "\\ \" " ) ) . AppendLine ( "\" );" ) ;
520+
521+ cscode
516522 . Append ( " }\r \n " )
517523 . Append ( " return base." ) . Append ( pnv . Name ) . AppendLine ( ";" )
518524 . Append ( " }\r \n " ) ;
@@ -574,14 +580,14 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common) {
574580 if ( trycol == null ) {
575581 nvref . Exception = new Exception ( $ "导航属性 { trytbTypeName } .{ pnv . Name } 没有找到对应的字段,如:{ pnv . Name } { findtbrefPkCsName } 、{ pnv . Name } _{ findtbrefPkCsName } ") ;
576582 trytb . AddOrUpdateTableRef ( pnv . Name , nvref ) ;
577- if ( isLazy ) throw nvref . Exception ;
583+ // if (isLazy) throw nvref.Exception;
578584 continue ;
579585 }
580586
581587 nvref . Columns . Add ( trycol ) ;
582588 nvref . RefColumns . Add ( tbref . Primarys [ a ] ) ;
583589
584- if ( isLazy ) {
590+ if ( isLazy && nvref . Exception == null ) {
585591 if ( a > 0 ) lmbdWhere . Append ( " && " ) ;
586592 lmbdWhere . Append ( "a." ) . Append ( tbref . Primarys [ a ] . CsName ) . Append ( " == this." ) . Append ( trycol . CsName ) ;
587593 }
@@ -597,9 +603,15 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common) {
597603 . Append ( " public override " ) . Append ( propTypeName ) . Append ( " " ) . Append ( pnv . Name ) . AppendLine ( " {" ) ;
598604 if ( vp . Item2 ) { //get 重写
599605 cscode . Append ( " get {\r \n " )
600- . Append ( " if (base." ) . Append ( pnv . Name ) . Append ( " == null && __lazy__" ) . Append ( pnv . Name ) . AppendLine ( " == false) {" )
601- . Append ( " base." ) . Append ( pnv . Name ) . Append ( " = __fsql_orm__.Select<" ) . Append ( propTypeName ) . Append ( ">().Where(a => " ) . Append ( lmbdWhere . ToString ( ) ) . AppendLine ( ").ToOne();" )
602- . Append ( " __lazy__" ) . Append ( pnv . Name ) . AppendLine ( " = true;" )
606+ . Append ( " if (base." ) . Append ( pnv . Name ) . Append ( " == null && __lazy__" ) . Append ( pnv . Name ) . AppendLine ( " == false) {" ) ;
607+
608+ if ( nvref . Exception == null )
609+ cscode . Append ( " base." ) . Append ( pnv . Name ) . Append ( " = __fsql_orm__.Select<" ) . Append ( propTypeName ) . Append ( ">().Where(a => " ) . Append ( lmbdWhere . ToString ( ) ) . AppendLine ( ").ToOne();" )
610+ . Append ( " __lazy__" ) . Append ( pnv . Name ) . AppendLine ( " = true;" ) ;
611+ else
612+ cscode . Append ( " throw new Exception(\" " ) . Append ( nvref . Exception . Message . Replace ( "\r \n " , "\\ r\\ n" ) . Replace ( "\" " , "\\ \" " ) ) . AppendLine ( "\" );" ) ;
613+
614+ cscode
603615 . Append ( " }\r \n " )
604616 . Append ( " return base." ) . Append ( pnv . Name ) . AppendLine ( ";" )
605617 . Append ( " }\r \n " ) ;
0 commit comments