File tree Expand file tree Collapse file tree 3 files changed +45
-9
lines changed Expand file tree Collapse file tree 3 files changed +45
-9
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
33using System . Data ;
4+ using System . Linq ;
45using System . Reflection ;
56
67#if EF4
@@ -42,18 +43,22 @@ public string GetUserDefinedTableType(PropertyInfo propertyInfo)
4243
4344 public Type GetCollectionType ( Type type )
4445 {
45- if ( type . IsGenericType )
46+ Type returnType = null ;
47+ if ( type . IsGenericType )
4648 {
47- foreach ( Type interfaceType in type . GetInterfaces ( ) )
48- {
49- if ( interfaceType . GetGenericTypeDefinition ( ) == typeof ( IList < > ) )
50- {
51- return interfaceType . GetGenericArguments ( ) [ 0 ] ;
52- }
49+ if ( type . IsInterface && type . GetGenericTypeDefinition ( ) == typeof ( IEnumerable < > ) )
50+ {
51+ returnType = type . GetGenericArguments ( ) . FirstOrDefault ( ) ;
5352 }
53+ else
54+ {
55+ returnType = type . GetInterfaces ( )
56+ . Where ( x => x . IsGenericType )
57+ . FirstOrDefault ( x => x . GetGenericTypeDefinition ( ) == typeof ( IEnumerable < > ) ) ? . GetGenericArguments ( ) . FirstOrDefault ( ) ;
58+ }
5459 }
5560
56- return null ;
61+ return returnType ;
5762
5863 }
5964
Original file line number Diff line number Diff line change @@ -15,6 +15,13 @@ namespace EntityFrameworkExtras.Tests.Integration.StoredProcedures
1515 public class UserDefinedTableExplicitlySetColumnNameStoredProcedure
1616 {
1717 [ StoredProcedureParameter ( SqlDbType . Udt ) ]
18- public List < ExplicitySetColumnNamesUserDefinedTable > UserDefinedTableParameter { get ; set ; }
18+ public IEnumerable < ExplicitySetColumnNamesUserDefinedTable > UserDefinedTableParameter { get ; set ; }
19+ }
20+
21+ [ StoredProcedure ( "UserDefinedTableStoredProcedure" ) ]
22+ public class UserDefinedTableExplicitlySetColumnNameStoredProcedure2
23+ {
24+ [ StoredProcedureParameter ( SqlDbType . Udt ) ]
25+ public List < ExplicitySetColumnNamesUserDefinedTable > UserDefinedTableParameter { get ; set ; }
1926 }
2027}
Original file line number Diff line number Diff line change @@ -78,5 +78,29 @@ public void Execute_ExplicitySetColumnName_CorrectValueReturned()
7878 Assert . AreEqual ( GetBytes ( "michael rodda" ) , result . ParameterBinary ) ;
7979
8080 }
81+
82+
83+ [ Test ]
84+ public void Execute_ExplicitySetColumnName_CorrectValueReturned2 ( )
85+ {
86+ var proc = new UserDefinedTableExplicitlySetColumnNameStoredProcedure2 ( ) ;
87+
88+ proc . UserDefinedTableParameter = new List < ExplicitySetColumnNamesUserDefinedTable > ( )
89+ {
90+ new ExplicitySetColumnNamesUserDefinedTable ( )
91+ {
92+ NvarChar = "Theses Columns Names were Explicity Set" ,
93+ BigInt = 1000 ,
94+ Binary = GetBytes ( "michael rodda" )
95+ }
96+ } ;
97+
98+ var result = ExecuteStoredProcedureSingle < AllTypesStoredProcedureReturn > ( proc ) ;
99+
100+ Assert . AreEqual ( "Theses Columns Names were Explicity Set" , result . ParameterNvarChar ) ;
101+ Assert . AreEqual ( 1000 , result . ParameterBigInt ) ;
102+ Assert . AreEqual ( GetBytes ( "michael rodda" ) , result . ParameterBinary ) ;
103+
104+ }
81105 }
82106}
You can’t perform that action at this time.
0 commit comments