@@ -356,14 +356,15 @@ void LocalNavigateReader(Type entityType, object entity)
356
356
357
357
public static void MapEntityValue ( string boundaryName , IFreeSql fsql , Type rootEntityType , object rootEntityFrom , object rootEntityTo )
358
358
{
359
+ var isDict = rootEntityTo ? . GetType ( ) == typeof ( Dictionary < string , object > ) ;
359
360
Dictionary < Type , Dictionary < string , bool > > ignores = new Dictionary < Type , Dictionary < string , bool > > ( ) ;
360
361
LocalMapEntityValue ( rootEntityType , rootEntityFrom , rootEntityTo , true ) ;
361
362
ignores . Clear ( ) ;
362
363
363
364
void LocalMapEntityValue ( Type entityType , object entityFrom , object entityTo , bool cascade )
364
365
{
365
366
if ( entityFrom == null || entityTo == null ) return ;
366
- if ( entityType == null ) entityType = entityFrom ? . GetType ( ) ?? entityTo ? . GetType ( ) ;
367
+ if ( entityType == null ) entityType = entityFrom . GetType ( ) ;
367
368
var table = fsql . CodeFirst . GetTableByEntity ( entityType ) ;
368
369
if ( table == null ) return ;
369
370
@@ -377,7 +378,8 @@ void LocalMapEntityValue(Type entityType, object entityFrom, object entityTo, bo
377
378
if ( table . ColumnsByCsIgnore . ContainsKey ( prop . Name ) ) continue ;
378
379
if ( table . ColumnsByCs . ContainsKey ( prop . Name ) )
379
380
{
380
- table . SetPropertyValue ( entityTo , prop . Name , table . GetPropertyValue ( entityFrom , prop . Name ) ) ;
381
+ if ( isDict ) ( entityTo as Dictionary < string , object > ) [ prop . Name ] = table . GetPropertyValue ( entityFrom , prop . Name ) ;
382
+ else table . SetPropertyValue ( entityTo , prop . Name , table . GetPropertyValue ( entityFrom , prop . Name ) ) ;
381
383
continue ;
382
384
}
383
385
if ( cascade == false ) continue ;
@@ -388,16 +390,18 @@ void LocalMapEntityValue(Type entityType, object entityFrom, object entityTo, bo
388
390
var propvalFrom = EntityUtilExtensions . GetEntityValueWithPropertyName ( fsql , entityType , entityFrom , prop . Name ) ;
389
391
if ( propvalFrom == null )
390
392
{
391
- EntityUtilExtensions . SetEntityValueWithPropertyName ( fsql , entityType , entityTo , prop . Name , null ) ;
393
+ if ( isDict ) ( entityTo as Dictionary < string , object > ) [ prop . Name ] = null ;
394
+ else EntityUtilExtensions . SetEntityValueWithPropertyName ( fsql , entityType , entityTo , prop . Name , null ) ;
392
395
continue ;
393
396
}
394
397
switch ( tbref . RefType )
395
398
{
396
399
case TableRefType . OneToOne :
397
- var propvalTo = tbref . RefEntityType . CreateInstanceGetDefaultValue ( ) ;
400
+ var propvalTo = isDict ? new Dictionary < string , object > ( ) : tbref . RefEntityType . CreateInstanceGetDefaultValue ( ) ;
398
401
SetNavigateRelationshipValue ( fsql , tbref , table . Type , entityFrom , propvalFrom ) ;
399
402
LocalMapEntityValue ( tbref . RefEntityType , propvalFrom , propvalTo , boundaryAttr ? . BreakThen != true ) ;
400
- EntityUtilExtensions . SetEntityValueWithPropertyName ( fsql , entityType , entityTo , prop . Name , propvalTo ) ;
403
+ if ( isDict ) ( entityTo as Dictionary < string , object > ) [ prop . Name ] = null ;
404
+ else EntityUtilExtensions . SetEntityValueWithPropertyName ( fsql , entityType , entityTo , prop . Name , propvalTo ) ;
401
405
break ;
402
406
case TableRefType . OneToMany :
403
407
SetNavigateRelationshipValue ( fsql , tbref , table . Type , entityFrom , propvalFrom ) ;
@@ -414,22 +418,36 @@ void LocalMapEntityValue(Type entityType, object entityFrom, object entityTo, bo
414
418
}
415
419
void LocalMapEntityValueCollection ( Type entityType , object entityFrom , object entityTo , TableRef tbref , IEnumerable propvalFrom , PropertyInfo prop , bool cascade )
416
420
{
417
- var propvalTo = typeof ( List < > ) . MakeGenericType ( tbref . RefEntityType ) . CreateInstanceGetDefaultValue ( ) ;
418
- var propvalToIList = propvalTo as IList ;
419
- foreach ( var fromItem in propvalFrom )
421
+ if ( isDict )
420
422
{
421
- var toItem = tbref . RefEntityType . CreateInstanceGetDefaultValue ( ) ;
422
- LocalMapEntityValue ( tbref . RefEntityType , fromItem , toItem , cascade ) ;
423
- propvalToIList . Add ( toItem ) ;
423
+ var propvalTo = new List < Dictionary < string , object > > ( ) ;
424
+ foreach ( var fromItem in propvalFrom )
425
+ {
426
+ var toItem = new Dictionary < string , object > ( ) ;
427
+ LocalMapEntityValue ( tbref . RefEntityType , fromItem , toItem , cascade ) ;
428
+ propvalTo . Add ( toItem ) ;
429
+ }
430
+ ( entityTo as Dictionary < string , object > ) [ prop . Name ] = propvalTo ;
424
431
}
425
- var propvalType = prop . PropertyType . GetGenericTypeDefinition ( ) ;
426
- if ( propvalType == typeof ( List < > ) || propvalType == typeof ( ICollection < > ) )
427
- EntityUtilExtensions . SetEntityValueWithPropertyName ( fsql , entityType , entityTo , prop . Name , propvalTo ) ;
428
- else if ( propvalType == typeof ( ObservableCollection < > ) )
432
+ else
429
433
{
430
- //var propvalTypeOcCtor = typeof(ObservableCollection<>).MakeGenericType(tbref.RefEntityType).GetConstructor(new[] { typeof(List<>).MakeGenericType(tbref.RefEntityType) });
431
- var propvalTypeOc = Activator . CreateInstance ( typeof ( ObservableCollection < > ) . MakeGenericType ( tbref . RefEntityType ) , new object [ ] { propvalTo } ) ;
432
- EntityUtilExtensions . SetEntityValueWithPropertyName ( fsql , entityType , entityTo , prop . Name , propvalTypeOc ) ;
434
+ var propvalTo = typeof ( List < > ) . MakeGenericType ( tbref . RefEntityType ) . CreateInstanceGetDefaultValue ( ) ;
435
+ var propvalToIList = propvalTo as IList ;
436
+ foreach ( var fromItem in propvalFrom )
437
+ {
438
+ var toItem = tbref . RefEntityType . CreateInstanceGetDefaultValue ( ) ;
439
+ LocalMapEntityValue ( tbref . RefEntityType , fromItem , toItem , cascade ) ;
440
+ propvalToIList . Add ( toItem ) ;
441
+ }
442
+ var propvalType = prop . PropertyType . GetGenericTypeDefinition ( ) ;
443
+ if ( propvalType == typeof ( List < > ) || propvalType == typeof ( ICollection < > ) )
444
+ EntityUtilExtensions . SetEntityValueWithPropertyName ( fsql , entityType , entityTo , prop . Name , propvalTo ) ;
445
+ else if ( propvalType == typeof ( ObservableCollection < > ) )
446
+ {
447
+ //var propvalTypeOcCtor = typeof(ObservableCollection<>).MakeGenericType(tbref.RefEntityType).GetConstructor(new[] { typeof(List<>).MakeGenericType(tbref.RefEntityType) });
448
+ var propvalTypeOc = Activator . CreateInstance ( typeof ( ObservableCollection < > ) . MakeGenericType ( tbref . RefEntityType ) , new object [ ] { propvalTo } ) ;
449
+ EntityUtilExtensions . SetEntityValueWithPropertyName ( fsql , entityType , entityTo , prop . Name , propvalTypeOc ) ;
450
+ }
433
451
}
434
452
}
435
453
}
0 commit comments