mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-06-03 15:13:28 +00:00
Support conditional access rewriting for value types
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
// <auto-generated/>
|
||||
using EntityFrameworkCore.Projectables;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Generated
|
||||
#nullable disable
|
||||
{
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public static class _Foo_SomeNumber
|
||||
{
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo, int>> Expression()
|
||||
{
|
||||
return (global::Foo fancyClass) =>
|
||||
fancyClass != null ? (fancyClass.FancyNumber ) : (int?)null ?? 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@ namespace EntityFrameworkCore.Projectables.Generated
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.EntityExtensions.Entity, global::Foo.EntityExtensions.Entity>> Expression()
|
||||
{
|
||||
return (global::Foo.EntityExtensions.Entity entity) =>
|
||||
entity != null ? (entity.RelatedEntities != null ? (entity.RelatedEntities[0]) : null) : null;
|
||||
entity != null ? (entity.RelatedEntities != null ? (entity.RelatedEntities[0]) : (global::Foo.EntityExtensions.Entity)null) : (global::Foo.EntityExtensions.Entity)null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@ namespace EntityFrameworkCore.Projectables.Generated
|
||||
public static System.Linq.Expressions.Expression<System.Func<string, int?>> Expression()
|
||||
{
|
||||
return (string input) =>
|
||||
input != null ? (input.Length) : null;
|
||||
input != null ? (input.Length) : (int?)null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@ namespace EntityFrameworkCore.Projectables.Generated
|
||||
public static System.Linq.Expressions.Expression<System.Func<global::Foo.EntityExtensions.Entity, string>> Expression()
|
||||
{
|
||||
return (global::Foo.EntityExtensions.Entity entity) =>
|
||||
entity.FullName != null ? (entity.FullName.Substring(entity.FullName != null ? (entity.FullName.IndexOf(' ') ) : null?? 0)) : null;
|
||||
entity.FullName != null ? (entity.FullName.Substring(entity.FullName != null ? (entity.FullName.IndexOf(' ') ) : (int?)null ?? 0)) : (string)null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@ namespace EntityFrameworkCore.Projectables.Generated
|
||||
public static System.Linq.Expressions.Expression<System.Func<string, char?>> Expression()
|
||||
{
|
||||
return (string input) =>
|
||||
input != null ? (input[0]) : null;
|
||||
input != null ? (input[0]) : (char?)null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -1542,6 +1542,30 @@ namespace One.Two {
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task NullConditionalNullCoalesceTypeConversion()
|
||||
{
|
||||
// issue: https://github.com/koenbeuk/EntityFrameworkCore.Projectables/issues/48
|
||||
|
||||
var compilation = CreateCompilation(@"
|
||||
using EntityFrameworkCore.Projectables;
|
||||
|
||||
class Foo {
|
||||
public int? FancyNumber { get; set; }
|
||||
|
||||
[Projectable(NullConditionalRewriteSupport = NullConditionalRewriteSupport.Rewrite)]
|
||||
public static int SomeNumber(Foo fancyClass) => fancyClass?.FancyNumber ?? 3;
|
||||
}
|
||||
");
|
||||
|
||||
var result = RunGenerator(compilation);
|
||||
|
||||
Assert.Empty(result.Diagnostics);
|
||||
Assert.Single(result.GeneratedTrees);
|
||||
|
||||
return Verifier.Verify(result.GeneratedTrees[0].ToString());
|
||||
}
|
||||
|
||||
#region Helpers
|
||||
|
||||
Compilation CreateCompilation(string source, bool expectedToCompile = true)
|
||||
|
||||
Reference in New Issue
Block a user