|
| 1 | +module LinqToDB.EntityFrameworkCore.FSharpTests |
| 2 | + |
| 3 | +open System.Linq |
| 4 | +open LinqToDB |
| 5 | +open System.ComponentModel.DataAnnotations |
| 6 | +open System.ComponentModel.DataAnnotations.Schema |
| 7 | +open Microsoft.EntityFrameworkCore |
| 8 | +open EntityFrameworkCore.FSharp.Extensions |
| 9 | +open NUnit.Framework |
| 10 | + |
| 11 | +[<CLIMutable>] |
| 12 | +type WithIdentity = { |
| 13 | + [<Key>] |
| 14 | + [<DatabaseGenerated(DatabaseGeneratedOption.Identity)>] |
| 15 | + Id : int |
| 16 | + Name : string |
| 17 | +} |
| 18 | + |
| 19 | +type AppDbContext(options: DbContextOptions<AppDbContext>) = |
| 20 | + inherit DbContext(options) |
| 21 | + |
| 22 | + [<DefaultValue>] val mutable WithIdentity : DbSet<WithIdentity> |
| 23 | + member this.CompaniesInformation |
| 24 | + with get() = this.WithIdentity |
| 25 | + and set v = this.WithIdentity <- v |
| 26 | + |
| 27 | +type TestDbContextFactory() = |
| 28 | + member this.CreateDbContext() = |
| 29 | + let options = new DbContextOptionsBuilder<AppDbContext>() |
| 30 | + options.UseSqlite("DataSource=:memory:").UseFSharpTypes() |> ignore |
| 31 | + new AppDbContext(options.Options) |
| 32 | + |
| 33 | +[<TestFixture>] |
| 34 | +type Tests() = |
| 35 | + |
| 36 | + [<Test>] |
| 37 | + member this.TestLeftJoin() = |
| 38 | + let context = TestDbContextFactory().CreateDbContext() |
| 39 | + let q = |
| 40 | + context |
| 41 | + .WithIdentity |
| 42 | + .Join( |
| 43 | + context.WithIdentity, |
| 44 | + (fun p -> p.Id), |
| 45 | + (fun c -> c.Id), |
| 46 | + (fun p c -> |
| 47 | + {| |
| 48 | + Person = p |
| 49 | + Company = c |
| 50 | + |}) ) |
| 51 | + .LeftJoin( |
| 52 | + context.WithIdentity, |
| 53 | + (fun partialPerson cInfo -> partialPerson.Company.Id = cInfo.Id), |
| 54 | + (fun partialPerson cInfo -> |
| 55 | + {| |
| 56 | + Company = partialPerson.Company |
| 57 | + CompanyInformation = cInfo |
| 58 | + Person = partialPerson.Person |
| 59 | + |}) ) |
| 60 | + //q.ToArray() |> ignore |
| 61 | + q.ToLinqToDB().ToString() |> ignore |
0 commit comments