@ -19,86 +19,46 @@ namespace SqlSugar
string result = string . Empty ;
var veiwModel = _ context . EntityMaintenance . GetEntityInfo < TResult > ( ) ;
var exp = ( queryBuilder . JoinExpression as LambdaExpression ) ;
List < KeyValuePair < string , object > > selectItems = new List < KeyValuePair < string , object > > ( ) ;
foreach ( var viewColumn in veiwModel . Columns )
List < KeyValuePair < string , JoinMapper > > selectItems = new List < KeyValuePair < string , JoinMapper > > ( ) ;
var exParsmeters = exp . Parameters . Select ( it = > new { shortName = it . Name , type = it . Type } ) . ToList ( ) ;
foreach ( var viewColumns in veiwModel . Columns )
{
var exParsmeters = exp . Parameters . Select ( it = > new { shortName = it . Name , type = it . Type } ) . ToList ( ) ;
var isbreak = false ;
foreach ( var expPars in exParsmeters )
{
var columns = _ context . EntityMaintenance . GetEntityInfo ( expPars . type ) . Columns . Where ( it = > it . IsIgnore = = false ) ;
var joinModelDbColumns = columns . Select ( it = >
new { asName = it . PropertyName , dbName = _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) } ) . ToList ( ) ;
var joinModelProperties = columns . Select ( it = >
new { asName = _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) , dbName = _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) } ) . ToList ( ) ;
var joinModelDbColumnsWithType = columns . Select ( it = >
new { asName = ( expPars . type . Name + it . PropertyName ) , dbName = _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) } ) . ToList ( ) ;
var joinModelPropertiesWithTye = columns . Select ( it = >
new { asName = ( expPars . type . Name + _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) ) , dbName = _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) } ) . ToList ( ) ;
var joinModelDbColumns_WithType = columns . Select ( it = >
new { asName = ( expPars . type . Name + "_" + it . PropertyName ) , dbName = _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) } ) . ToList ( ) ;
var joinModelProperties_WithType = columns . Select ( it = >
new { asName = ( expPars . type . Name + "_" + _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) ) , dbName = _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) } ) . ToList ( ) ;
var joinModelDbColumnsWithSN = columns . Select ( it = >
new { asName = ( expPars . shortName + it . PropertyName ) , dbName = _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) } ) . ToList ( ) ;
var joinModelPropertiesWithSN = columns . Select ( it = >
new { asName = ( expPars . shortName + _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) ) , dbName = _ context . EntityMaintenance . GetDbColumnName ( it . PropertyName , expPars . type ) } ) . ToList ( ) ;
if ( joinModelDbColumns . Any ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) )
{
var value = joinModelDbColumns . First ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) ;
if ( viewColumn . PropertyName . Equals ( value . asName , StringComparison . CurrentCultureIgnoreCase ) )
selectItems . Add ( new KeyValuePair < string , object > ( expPars . shortName , value ) ) ;
break ;
}
if ( joinModelProperties . Any ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) )
{
if ( isbreak )
{
var value = joinModelProperties . First ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) ;
if ( viewColumn . PropertyName . Equals ( value . asName , StringComparison . CurrentCultureIgnoreCase ) )
selectItems . Add ( new KeyValuePair < string , object > ( expPars . shortName , value ) ) ;
break ;
}
if ( joinModelDbColumnsWithType . Any ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) )
{
var value = joinModelDbColumnsWithType . First ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) ;
if ( viewColumn . PropertyName . Equals ( value . asName , StringComparison . CurrentCultureIgnoreCase ) )
selectItems . Add ( new KeyValuePair < string , object > ( expPars . shortName , value ) ) ;
break ;
}
if ( joinModelPropertiesWithTye . Any ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) )
{
var value = joinModelPropertiesWithTye . First ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) ;
if ( viewColumn . PropertyName . Equals ( value . asName , StringComparison . CurrentCultureIgnoreCase ) )
selectItems . Add ( new KeyValuePair < string , object > ( expPars . shortName , value ) ) ;
break ;
}
var entityInfo = _ context . EntityMaintenance . GetEntityInfo ( expPars . type ) ;
var columns = entityInfo . Columns . Where ( it = > it . IsIgnore = = false ) ;
var list = columns . Select ( it = > {
var array = new string [ ]
{
it . PropertyName ,
it . DbColumnName ,
if ( joinModelDbColumns_WithType . Any ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) )
{
var value = joinModelDbColumns_WithType . First ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) ;
if ( viewColumn . PropertyName . Equals ( value . asName , StringComparison . CurrentCultureIgnoreCase ) )
selectItems . Add ( new KeyValuePair < string , object > ( expPars . shortName , value ) ) ;
break ;
}
if ( joinModelProperties_WithType . Any ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) )
{
var value = joinModelProperties_WithType . First ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) ;
if ( viewColumn . PropertyName . Equals ( value . asName , StringComparison . CurrentCultureIgnoreCase ) )
selectItems . Add ( new KeyValuePair < string , object > ( expPars . shortName , value ) ) ;
break ;
}
if ( joinModelDbColumnsWithSN . Any ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) )
{
var value = joinModelDbColumnsWithSN . First ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) ;
if ( viewColumn . PropertyName . Equals ( value . asName , StringComparison . CurrentCultureIgnoreCase ) )
selectItems . Add ( new KeyValuePair < string , object > ( expPars . shortName , value ) ) ;
break ;
}
if ( joinModelPropertiesWithSN . Any ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) )
expPars . type . Name + it . PropertyName ,
expPars . type . Name + it . DbColumnName ,
expPars . type . Name + "_" + it . PropertyName ,
expPars . type . Name + "_" + it . DbColumnName ,
expPars . shortName + it . PropertyName ,
expPars . shortName + it . DbColumnName ,
} ;
return new { it , array } ;
} ) . ToList ( ) ;
var columnInfo = list . FirstOrDefault ( y = > y . array . Select ( z = > z . ToLower ( ) ) . Contains ( viewColumns . PropertyName . ToLower ( ) ) ) ;
if ( columnInfo ! = null )
{
var value = joinModelPropertiesWithSN . First ( it = > it . asName . Equals ( viewColumn . PropertyName , StringComparison . CurrentCultureIgnoreCase ) ) ;
if ( viewColumn . PropertyName . Equals ( value . asName , StringComparison . CurrentCultureIgnoreCase ) )
selectItems . Add ( new KeyValuePair < string , object > ( expPars . shortName , value ) ) ;
break ;
JoinMapper joinMapper = new JoinMapper ( )
{
AsName = viewColumns . PropertyName ,
DbName = columnInfo . it . DbColumnName
} ;
selectItems . Add ( new KeyValuePair < string , JoinMapper > ( expPars . shortName , joinMapper ) ) ;
isbreak = true ;
}
}
}