@@ -378,12 +378,12 @@ public int CreateTable(Type ty, CreateFlags createFlags = CreateFlags.None)
378
378
379
379
if ( map . HasCompositePK )
380
380
{
381
- var PKs = mapColumns . Where ( c => c . IsPK ) . ToList ( ) ;
381
+ var compositePK = mapColumns . Where ( c => c . IsPK ) . ToList ( ) ;
382
382
383
383
var decls = mapColumns . Select ( p => Orm . SqlDecl ( p , StoreDateTimeAsTicks , Serializer , ExtraTypeMappings , map . HasCompositePK ) ) ;
384
384
var decl = string . Join ( ",\n " , decls . ToArray ( ) ) ;
385
385
query . Append ( decl ) . Append ( ",\n " ) ;
386
- query . Append ( "primary key (" ) . Append ( string . Join ( "," , PKs . Select ( pk => pk . Name ) ) ) . Append ( ")" ) ;
386
+ query . Append ( "primary key (" ) . Append ( string . Join ( "," , compositePK . Select ( pk => pk . Name ) ) ) . Append ( ")" ) ;
387
387
query . Append ( ")" ) ;
388
388
}
389
389
else
@@ -547,8 +547,6 @@ private void MigrateTable(TableMapping map)
547
547
548
548
var toBeAdded = new List < TableMapping . Column > ( ) ;
549
549
550
- var PKscount = map . Columns . Where ( c => c . IsPK ) . Count ( ) ;
551
-
552
550
foreach ( var p in map . Columns )
553
551
{
554
552
var found = false ;
@@ -825,17 +823,17 @@ public T Get<T>(object pk) where T : class
825
823
var map = GetMapping ( typeof ( T ) ) ;
826
824
if ( map . HasCompositePK )
827
825
{
828
- IDictionary < string , object > PKs = pk as Dictionary < string , object > ;
829
- if ( PKs == null )
826
+ IDictionary < string , object > compositePK = pk as Dictionary < string , object > ;
827
+ if ( compositePK == null )
830
828
{
831
829
throw new NotSupportedException ( map . TableName + " table has a composite primary key. Make sure primary key is passed in as Dictionary<string, object>." ) ;
832
830
}
833
- var pks = map . PKs ;
834
- if ( PKs . Keys . Intersect ( pks . Select ( p => p . Name ) ) . Count ( ) < pks . Length )
831
+ var cpk = map . CompositePK ;
832
+ if ( compositePK . Keys . Intersect ( cpk . Select ( p => p . Name ) ) . Count ( ) < cpk . Length )
835
833
{
836
- throw new NotSupportedException ( "Cannot get from " + map . TableName + ": PKs mismatch. Make sure PK names are valid." ) ;
834
+ throw new NotSupportedException ( "Cannot get from " + map . TableName + ": CompositePK mismatch. Make sure PK names are valid." ) ;
837
835
}
838
- return Query < T > ( map . GetByPrimaryKeySql , PKs . Values . ToArray ( ) ) . First ( ) ;
836
+ return Query < T > ( map . GetByPrimaryKeySql , compositePK . Values . ToArray ( ) ) . First ( ) ;
839
837
}
840
838
else
841
839
{
@@ -878,17 +876,17 @@ public T Find<T>(object pk) where T : class
878
876
var map = GetMapping ( typeof ( T ) ) ;
879
877
if ( map . HasCompositePK )
880
878
{
881
- IDictionary < string , object > PKs = pk as Dictionary < string , object > ;
882
- if ( PKs == null )
879
+ IDictionary < string , object > compositePK = pk as Dictionary < string , object > ;
880
+ if ( compositePK == null )
883
881
{
884
882
throw new NotSupportedException ( map . TableName + " table has a composite primary key. Make sure primary key is passed in as Dictionary<string, object>." ) ;
885
883
}
886
- var pks = map . PKs ;
887
- if ( PKs . Keys . Intersect ( pks . Select ( p => p . Name ) ) . Count ( ) < pks . Length )
884
+ var cpk = map . CompositePK ;
885
+ if ( compositePK . Keys . Intersect ( cpk . Select ( p => p . Name ) ) . Count ( ) < cpk . Length )
888
886
{
889
- throw new NotSupportedException ( "Cannot find in " + map . TableName + ": PKs mismatch. Make sure PK names are valid." ) ;
887
+ throw new NotSupportedException ( "Cannot find in " + map . TableName + ": CompositePK mismatch. Make sure PK names are valid." ) ;
890
888
}
891
- return Query < T > ( map . GetByPrimaryKeySql , PKs . Values . ToArray ( ) ) . FirstOrDefault ( ) ;
889
+ return Query < T > ( map . GetByPrimaryKeySql , compositePK . Values . ToArray ( ) ) . FirstOrDefault ( ) ;
892
890
}
893
891
else
894
892
{
@@ -936,17 +934,17 @@ public object Find(object pk, TableMapping map)
936
934
{
937
935
if ( map . HasCompositePK )
938
936
{
939
- IDictionary < string , object > PKs = pk as Dictionary < string , object > ;
940
- if ( PKs == null )
937
+ IDictionary < string , object > compositePK = pk as Dictionary < string , object > ;
938
+ if ( compositePK == null )
941
939
{
942
940
throw new NotSupportedException ( map . TableName + " table has a composite primary key. Make sure primary key is passed in as Dictionary<string, object>." ) ;
943
941
}
944
- var pks = map . PKs ;
945
- if ( PKs . Keys . Intersect ( pks . Select ( p => p . Name ) ) . Count ( ) < pks . Length )
942
+ var cpk = map . CompositePK ;
943
+ if ( compositePK . Keys . Intersect ( cpk . Select ( p => p . Name ) ) . Count ( ) < cpk . Length )
946
944
{
947
- throw new NotSupportedException ( "Cannot find in " + map . TableName + ": PKs mismatch. Make sure PK names are valid." ) ;
945
+ throw new NotSupportedException ( "Cannot find in " + map . TableName + ": CompositePK mismatch. Make sure PK names are valid." ) ;
948
946
}
949
- return Query ( map , map . GetByPrimaryKeySql , PKs . Values . ToArray ( ) ) . FirstOrDefault ( ) ;
947
+ return Query ( map , map . GetByPrimaryKeySql , compositePK . Values . ToArray ( ) ) . FirstOrDefault ( ) ;
950
948
}
951
949
else
952
950
{
@@ -1513,7 +1511,7 @@ public int Insert(object obj, string extra, Type objType)
1513
1511
1514
1512
if ( map . HasCompositePK )
1515
1513
{
1516
- pk = map . PKs . FirstOrDefault ( p => p . IsAutoGuid ) ;
1514
+ pk = map . CompositePK . FirstOrDefault ( p => p . IsAutoGuid ) ;
1517
1515
}
1518
1516
else
1519
1517
{
@@ -1635,19 +1633,19 @@ public int Update(object obj, Type objType)
1635
1633
1636
1634
if ( map . HasCompositePK )
1637
1635
{
1638
- var pks = map . PKs ;
1636
+ var compositePK = map . CompositePK ;
1639
1637
var cols = from p in map . Columns
1640
- where ! pks . Any ( pk => pk == p )
1638
+ where ! compositePK . Any ( pk => pk == p )
1641
1639
select p ;
1642
1640
1643
1641
var pslist = ( from c in cols
1644
1642
select c . GetValue ( obj ) ) . ToList ( ) ;
1645
1643
1646
- pslist . AddRange ( pks . Select ( pk => pk . GetValue ( obj ) ) ) ;
1644
+ pslist . AddRange ( compositePK . Select ( pk => pk . GetValue ( obj ) ) ) ;
1647
1645
1648
1646
q = string . Format ( "update \" {0}\" set {1} where {2}" , map . TableName ,
1649
1647
string . Join ( "," , ( from c in cols
1650
- select "\" " + c . Name + "\" = ? " ) . ToArray ( ) ) , string . Join ( " and " , pks . Select ( pk => "\" " + pk . Name + "\" = ? " ) ) ) ;
1648
+ select "\" " + c . Name + "\" = ? " ) . ToArray ( ) ) , string . Join ( " and " , compositePK . Select ( pk => "\" " + pk . Name + "\" = ? " ) ) ) ;
1651
1649
1652
1650
ps = pslist . ToArray ( ) ;
1653
1651
}
@@ -1747,9 +1745,9 @@ public int Delete(object objectToDelete)
1747
1745
1748
1746
if ( map . HasCompositePK )
1749
1747
{
1750
- var pks = map . PKs ;
1751
- q = string . Format ( "delete from \" {0}\" where {1}" , map . TableName , string . Join ( " and " , pks . Select ( pk => "\" " + pk . Name + "\" = ? " ) ) ) ;
1752
- ps = ( from pk in pks
1748
+ var compositePK = map . CompositePK ;
1749
+ q = string . Format ( "delete from \" {0}\" where {1}" , map . TableName , string . Join ( " and " , compositePK . Select ( pk => "\" " + pk . Name + "\" = ? " ) ) ) ;
1750
+ ps = ( from pk in compositePK
1753
1751
select pk . GetValue ( objectToDelete ) ) . ToArray ( ) ;
1754
1752
}
1755
1753
else
@@ -1785,18 +1783,18 @@ public int Delete<T>(object primaryKey)
1785
1783
1786
1784
if ( map . HasCompositePK )
1787
1785
{
1788
- var pks = map . PKs ;
1789
- IDictionary < string , object > PKs = primaryKey as Dictionary < string , object > ;
1790
- if ( PKs == null )
1786
+ var cpk = map . CompositePK ;
1787
+ IDictionary < string , object > compositePK = primaryKey as Dictionary < string , object > ;
1788
+ if ( compositePK == null )
1791
1789
{
1792
1790
throw new NotSupportedException ( map . TableName + " table has a composite primary key. Make sure primary key is passed in as Dictionary<string, object>." ) ;
1793
1791
}
1794
- if ( PKs . Keys . Intersect ( pks . Select ( p => p . Name ) ) . Count ( ) < pks . Length )
1792
+ if ( compositePK . Keys . Intersect ( cpk . Select ( p => p . Name ) ) . Count ( ) < cpk . Length )
1795
1793
{
1796
- throw new NotSupportedException ( "Cannot delete " + map . TableName + ": PKs mismatch. Make sure PK names are valid." ) ;
1794
+ throw new NotSupportedException ( "Cannot delete " + map . TableName + ": CompositePK mismatch. Make sure PK names are valid." ) ;
1797
1795
}
1798
- var q = string . Format ( "delete from \" {0}\" where {1}" , map . TableName , string . Join ( " and " , PKs . Keys . Select ( pk => "\" " + pk + "\" = ? " ) ) ) ;
1799
- var ps = ( from pk in PKs . Values
1796
+ var q = string . Format ( "delete from \" {0}\" where {1}" , map . TableName , string . Join ( " and " , compositePK . Keys . Select ( pk => "\" " + pk + "\" = ? " ) ) ) ;
1797
+ var ps = ( from pk in compositePK . Values
1800
1798
select pk ) . ToArray ( ) ;
1801
1799
return Execute ( q , ps ) ;
1802
1800
}
0 commit comments