Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test for issue #4390 #4391

Merged
merged 5 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion Tests/Linq/Tools/EntityServices/IdentityMapTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using LinqToDB;

using NUnit.Framework;

using Tests.Linq;

namespace Tests.Tools.EntityServices
{
using LinqToDB.Common;
Expand Down Expand Up @@ -102,5 +109,19 @@ public void NegativeTest()
Assert.Throws<LinqToDBConvertException>(() => map.GetEntity<Person>(new { ID1 = 1 }));
}
}

[Test]
public async Task CompiledQueryTest()
{
await using var db = new TestDataConnection();
using var map = new IdentityMap(db);

var query = CompiledQuery.Compile<TestDataConnection,CancellationToken,Task<List<Person>>>(static (db, ct) => db.Person.Where(p => p.ID == 1).ToListAsync(ct));

var result1 = await query(db, default);
var result2 = await query(db, default);

Assert.That(result1[0], Is.SameAs(result2[0]));
}
}
}
68 changes: 68 additions & 0 deletions Tests/Linq/UserTests/Issue4390Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Linq;

using LinqToDB;
using LinqToDB.Mapping;
using NUnit.Framework;

using System;

using FluentAssertions;

namespace Tests.UserTests
{
[TestFixture]
public class Issue4390Tests : TestBase
{
[Table]
public class InfeedAdviceDTO
{
[Column] public int Id { get; set; }
}

[Table]
public class InventoryResourceDTO
{
[Column] public int InfeedAdviceID { get; set; }
}
public class MlogCombined1
{
public InfeedAdviceDTO? InfeedAdvice { get; set; }

public int? Count { get; set; }
}

public class MlogCombined2
{
public MlogCombined1? MlogCombined1 { get; set; }
}

[Test]
public void Issue4390Test([IncludeDataSources(TestProvName.AllSQLite)] string context)
{
using (var db = GetDataContext(context))
using (db.CreateLocalTable<InfeedAdviceDTO>())
using (db.CreateLocalTable<InventoryResourceDTO>())
{
db.Insert(new InventoryResourceDTO() { InfeedAdviceID = 1 });
db.Insert(new InfeedAdviceDTO() { Id = 1 });

var irs = from ir in db.GetTable<InventoryResourceDTO>() select ir;

var qry = from infeed in db.GetTable<InfeedAdviceDTO>()
join inventory in db.GetTable<InventoryResourceDTO>() on infeed.Id equals inventory.InfeedAdviceID
select new MlogCombined2
{
MlogCombined1 = new MlogCombined1
{
InfeedAdvice = infeed,
Count = irs.Count(x => x.InfeedAdviceID == infeed.Id),
}
};

var count = qry.Where(x => x.MlogCombined1 != null).Count();

count.Should().Be(1);
}
}
}
}