Skip to content

Commit cb8ec4e

Browse files
Merge pull request #35 from Lempireqc/master
save
2 parents ce9a9ba + 0768f9c commit cb8ec4e

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

EntityFrameworkExtras.Shared/StoredProcedureParserHelper.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Data;
4+
using System.Linq;
45
using 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

EntityFrameworkExtras.Tests.Shared/Integration/StoredProcedures/UserDefinedTableExplicitlySetColumnNameStoredProcedure.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

EntityFrameworkExtras.Tests.Shared/Integration/UserDefinedTableTypeColumnTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)