diff --git a/src/FSharpTypes/FSharpTypes.fsproj b/src/FSharpTypes/FSharpTypes.fsproj
index 186eabb173..2edfa524b2 100644
--- a/src/FSharpTypes/FSharpTypes.fsproj
+++ b/src/FSharpTypes/FSharpTypes.fsproj
@@ -1,13 +1,17 @@
- net8.0
true
8.0
+ net8.0;net7.0;net9.0
+
+
+
+
diff --git a/src/FSharpTypes/Library.fs b/src/FSharpTypes/Library.fs
index 498c8ab017..24822290ab 100644
--- a/src/FSharpTypes/Library.fs
+++ b/src/FSharpTypes/Library.fs
@@ -1,6 +1,9 @@
module FSharpTypes
open System
+open System.Linq.Expressions
+open Marten.Testing.Documents
+open Microsoft.FSharp.Linq.RuntimeHelpers
type OrderId = Id of Guid
@@ -14,3 +17,24 @@ type RecordTypeOrderId = { Part1: string; Part2: string }
type ArbitraryClass() =
member this.Value = "ok"
+
+let rec stripFSharpFunc (expression: Expression) =
+ match expression with
+ | :? MethodCallExpression as callExpression when callExpression.Method.Name = "ToFSharpFunc" ->
+ stripFSharpFunc callExpression.Arguments.[0]
+ | _ -> expression
+
+let toLinqExpression expr =
+ expr
+ |> LeafExpressionConverter.QuotationToExpression
+ |> stripFSharpFunc
+ |> unbox>>
+let greaterThanWithFsharpDateOption =
+ <@ fun (o1: Target) -> o1.FSharpDateTimeOffsetOption >= Some DateTimeOffset.UtcNow @> |> toLinqExpression
+let lesserThanWithFsharpDateOption = <@ (fun (o1: Target) -> o1.FSharpDateTimeOffsetOption <= Some DateTimeOffset.UtcNow ) @> |> toLinqExpression
+let greaterThanWithFsharpDecimalOption = <@ (fun (o1: Target) -> o1.FSharpDecimalOption >= Some 5m ) @> |> toLinqExpression
+let lesserThanWithFsharpDecimalOption = <@ (fun (o1: Target) -> o1.FSharpDecimalOption <= Some 5m ) @> |> toLinqExpression
+let greaterThanWithFsharpStringOption = <@ (fun (o1: Target) -> o1.FSharpStringOption >= Some "MyString" ) @> |> toLinqExpression
+let lesserThanWithFsharpStringOption = <@ (fun (o1: Target) -> o1.FSharpStringOption <= Some "MyString" ) @> |> toLinqExpression
+
+
diff --git a/src/LinqTests/Acceptance/Support/DefaultQueryFixture.cs b/src/LinqTests/Acceptance/Support/DefaultQueryFixture.cs
index c508c97db6..873e926025 100644
--- a/src/LinqTests/Acceptance/Support/DefaultQueryFixture.cs
+++ b/src/LinqTests/Acceptance/Support/DefaultQueryFixture.cs
@@ -1,3 +1,4 @@
+using System.Text.Json.Serialization;
using Marten;
using Marten.Services;
using Marten.Testing.Documents;
@@ -11,7 +12,6 @@ public DefaultQueryFixture()
{
Store = ProvisionStore("linq_querying");
-
DuplicatedFieldStore = ProvisionStore("duplicate_fields", o =>
{
o.Schema.For()
@@ -25,6 +25,30 @@ public DefaultQueryFixture()
.Duplicate(x => x.NumberArray);
});
+ FSharpFriendlyStore = ProvisionStore("fsharp_linq_querying", options =>
+ {
+ options.RegisterFSharpOptionValueTypes();
+ var serializerOptions = JsonFSharpOptions.Default().WithUnwrapOption().ToJsonSerializerOptions();
+ options.UseSystemTextJsonForSerialization(serializerOptions);
+ }, isFsharpTest: true);
+
+ FSharpFriendlyStoreWithDuplicatedField = ProvisionStore("fsharp_duplicated_fields", options =>
+ {
+ options.Schema.For()
+ .Duplicate(x => x.Number)
+ .Duplicate(x => x.Long)
+ .Duplicate(x => x.String)
+ .Duplicate(x => x.Date)
+ .Duplicate(x => x.Double)
+ .Duplicate(x => x.Flag)
+ .Duplicate(x => x.Color)
+ .Duplicate(x => x.NumberArray);
+
+ options.RegisterFSharpOptionValueTypes();
+ var serializerOptions = JsonFSharpOptions.Default().WithUnwrapOption().ToJsonSerializerOptions();
+ options.UseSystemTextJsonForSerialization(serializerOptions);
+ }, isFsharpTest: true);
+
SystemTextJsonStore = ProvisionStore("stj_linq", o =>
{
o.Serializer();
@@ -35,5 +59,9 @@ public DefaultQueryFixture()
public DocumentStore DuplicatedFieldStore { get; set; }
+ public DocumentStore FSharpFriendlyStore { get; set; }
+ public DocumentStore FSharpFriendlyStoreWithDuplicatedField { get; set; }
+
public DocumentStore Store { get; set; }
}
+
diff --git a/src/LinqTests/Acceptance/Support/LinqTestContext.cs b/src/LinqTests/Acceptance/Support/LinqTestContext.cs
index 1c5d80a8de..e4fcef9afd 100644
--- a/src/LinqTests/Acceptance/Support/LinqTestContext.cs
+++ b/src/LinqTests/Acceptance/Support/LinqTestContext.cs
@@ -103,17 +103,27 @@ public static IEnumerable