Skip to content

Commit cb3105e

Browse files
author
fabien.menager
committed
Add new tests for nullable types and fix GetFullTypeName
1 parent 746a6a7 commit cb3105e

13 files changed

Lines changed: 61 additions & 2 deletions

src/EntityFrameworkCore.Projectables/Services/ProjectionExpressionResolver.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ static string GetFullTypeName(Type type)
128128
return type.Name;
129129
}
130130

131+
// Handle nullable value types (e.g., int? -> int?)
132+
var underlyingType = Nullable.GetUnderlyingType(type);
133+
if (underlyingType != null)
134+
{
135+
return $"{GetFullTypeName(underlyingType)}?";
136+
}
137+
131138
// Handle array types
132139
if (type.IsArray)
133140
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT [t].[Id]
2+
FROM [TestEntity] AS [t]
3+
WHERE 1 > [t].[Id] AND NEWID() <> '00000000-0000-0000-0000-000000000000'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT [t].[Id]
2+
FROM [TestEntity] AS [t]
3+
WHERE 1 > [t].[Id] AND NEWID() <> '00000000-0000-0000-0000-000000000000'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT [t].[Id]
2+
FROM [TestEntity] AS [t]
3+
WHERE 1 > [t].[Id] AND NEWID() <> '00000000-0000-0000-0000-000000000000'

tests/EntityFrameworkCore.Projectables.FunctionalTests/ComplexArgumentsTests.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class TestEntity
2525

2626
[Projectable]
2727
public bool IsValid3(params int[] validIds) => validIds.Contains(Id);
28+
29+
[Projectable]
30+
public bool IsValid4(int? validId, Guid? guid) => validId > Id && guid != Guid.Parse("00000000-0000-0000-0000-000000000000");
2831
}
2932

3033
[Fact]
@@ -52,8 +55,7 @@ public Task ArrayOfPrimitivesArguments()
5255

5356
return Verifier.Verify(query.ToQueryString());
5457
}
55-
56-
58+
5759
[Fact]
5860
public Task ParamsOfPrimitivesArguments()
5961
{
@@ -64,5 +66,16 @@ public Task ParamsOfPrimitivesArguments()
6466

6567
return Verifier.Verify(query.ToQueryString());
6668
}
69+
70+
[Fact]
71+
public Task NullableValueTypes()
72+
{
73+
using var dbContext = new SampleDbContext<TestEntity>();
74+
75+
var query = dbContext.Set<TestEntity>()
76+
.Where(x => x.IsValid4(1, Guid.NewGuid()));
77+
78+
return Verifier.Verify(query.ToQueryString());
79+
}
6780
}
6881
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SELECT [g].[Id]
2+
FROM [GenericObject<int>] AS [g]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SELECT [g].[Id]
2+
FROM [GenericObject<int>] AS [g]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SELECT [g].[Id]
2+
FROM [GenericObject<int>] AS [g]

tests/EntityFrameworkCore.Projectables.FunctionalTests/ComplexModelTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public class Order
5252

5353
public DateTime RecordDate { get; set; }
5454
}
55+
56+
public class GenericObject<T>
57+
{
58+
public T Id { get; set; }
59+
}
5560

5661
[Fact]
5762
public Task ProjectOverNavigationProperty()
@@ -98,5 +103,16 @@ public Task ProjectQueryFilters()
98103

99104
return Verifier.Verify(query.ToQueryString());
100105
}
106+
107+
[Fact]
108+
public Task ProjectOverGenericType()
109+
{
110+
using var dbContext = new SampleDbContext<GenericObject<int>>();
111+
112+
var query = dbContext.Set<GenericObject<int>>()
113+
.Select(x => x.Id);
114+
115+
return Verifier.Verify(query.ToQueryString());
116+
}
101117
}
102118
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SELECT [e].[Id], [e].[Id] + 10 AS [Result]
2+
FROM [Entity] AS [e]

0 commit comments

Comments
 (0)