Skip to content

problem with join with withClause in case of inheritance #2331

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

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
88abcf0
improve adding of with clauses when entity overrides property from base
Mar 19, 2020
881ba03
remove ToColumns with 3 arguments
Mar 31, 2020
487bcb9
consider overriden properties when getting subclass property table nu…
Mar 31, 2020
4844868
special handling of with clauses
Apr 9, 2020
45a15b0
revert config changes
Apr 10, 2020
9fb6f1c
Merge branch 'master' into yg-join
georgi-yakimov Apr 15, 2020
bc99fed
Remove unused useLastIndex parameter
hazzik Apr 15, 2020
6abb744
Remove unused useLastIndex parameter
hazzik Apr 15, 2020
26f4b63
Add cross join support for Hql and Linq query provider (#2327)
maca88 Mar 21, 2020
7c9f229
improve adding of with clauses when entity overrides property from base
Mar 19, 2020
3e35554
Support evaluation of DateTime.Now on db side
fredericDelaporte Oct 3, 2018
130ee88
Support evaluation of Guid.NewGuid() on db side
fredericDelaporte Oct 4, 2018
032e464
Support evaluation of Random.Next and NextDouble on db side
fredericDelaporte Oct 6, 2018
f4b8bd7
Fix some NRE in work isolation and connection handling
fredericDelaporte Mar 22, 2020
1af6757
Clean up a bit isolation work code
fredericDelaporte Mar 22, 2020
9e12fb4
Support setting parameters with a dynamic object (#2321)
fredericDelaporte Mar 29, 2020
89fda96
Fix Linq Fetch/FetchMany after SelectMany method
maca88 Mar 6, 2020
d935eb8
Refactored session List<T> method for Criteria (#1627)
bahusoid Mar 30, 2020
d71c527
Call generic query.List from Linq queries (#2238)
bahusoid Mar 30, 2020
0b368c7
remove ToColumns with 3 arguments
Mar 31, 2020
39e7f52
consider overriden properties when getting subclass property table nu…
Mar 31, 2020
f8a3a22
Fix custom sql loader with composite id (#452)
hailtondecastro Mar 31, 2020
aff0871
Force join for comparisons in hql when not null entity key can repres…
bahusoid Mar 31, 2020
2b73276
Reduce cast usage for COUNT aggregate and add support for Mssql count…
maca88 Apr 1, 2020
7a95a0f
Fix a missing async regeneration in #2081
fredericDelaporte Apr 4, 2020
97c238c
Use entities prepared by Loader in hql select projections (#2082)
bahusoid Apr 5, 2020
e206809
Add support for caching fetched relations with Criteria (#2090)
bahusoid Apr 6, 2020
7bc3fdd
special handling of with clauses
Apr 9, 2020
cc0a572
revert config changes
Apr 10, 2020
3ba3b61
Improve async locking (#2147)
maca88 Apr 12, 2020
3bb2aa0
Configure log4net from embedded resource log4net.xml (#2235)
bahusoid Apr 13, 2020
b14eea0
Add support for MemberInit expression in GroupBySelectClauseRewriter …
maca88 Mar 6, 2020
4a6bf67
Add support for OData group by queries (#2135)
maca88 Apr 13, 2020
ac1877b
Support basic arithmetic operations (+, -, *, /) in QueryOver (#2156)
bahusoid Apr 13, 2020
0395016
Fix SQLite typing (#2346)
fredericDelaporte Apr 14, 2020
a217713
consider usage of QueryOver
Apr 16, 2020
6cc4dcc
Merge remote-tracking branch 'remotes/origin/yg-join' into yg-join
Apr 16, 2020
1382cc8
Revert "Remove unused useLastIndex parameter"
Apr 23, 2020
4a06333
Merge branch 'master' into yg-join
georgi-yakimov Apr 24, 2020
4b1a7f8
Merge branch 'master' into yg-join
georgi-yakimov Apr 29, 2020
374cb68
Merge branch 'master' into yg-join
hazzik May 8, 2020
c885345
Move tests to where they belong
hazzik May 8, 2020
2349e56
Revert changes
hazzik May 8, 2020
310482d
Cleanup tests
hazzik May 8, 2020
c8386ee
Cleanup tests
hazzik May 8, 2020
b1df203
Generate async
hazzik May 8, 2020
a84b3b6
Merge branch 'master' into yg-join
fredericDelaporte Oct 24, 2020
1fadd9b
Undo fix to only keep tests
fredericDelaporte Oct 24, 2020
2591e3b
Undo remaining whitespace change
fredericDelaporte Oct 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System.Linq;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Criterion;
using NHibernate.Mapping.ByCode;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH2330
{
using System.Threading.Tasks;
[TestFixture]
public class JoinedSubclassWithClauseFixtureAsync : TestCaseMappingByCode
{
private object _visit1Id;
private object _visit2Id;

protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();

mapper.Class<Node>(ca =>
{
ca.Id(x => x.Id, map => map.Generator(Generators.Identity));
ca.Property(x => x.Deleted);
ca.Property(x => x.FamilyName);
ca.Table("Node");
ca.Abstract(true);
});

mapper.JoinedSubclass<PersonBase>(
ca =>
{
ca.Key(x => x.Column("FK_Node_ID"));
ca.Extends(typeof(Node));
ca.Property(x => x.Deleted);
ca.Property(x => x.Login);
});

mapper.Class<UserEntityVisit>(
ca =>
{
ca.Id(x => x.Id, map => map.Generator(Generators.Identity));
ca.Property(x => x.Deleted);
ca.ManyToOne(x => x.PersonBase);
});

return mapper.CompileMappingForAllExplicitlyAddedEntities();
}

protected override void OnSetUp()
{
using (var arrangeSession = OpenSession())
using (var tx = arrangeSession.BeginTransaction())
{
var person = new PersonBase {Login = "dave", FamilyName = "grohl"};
arrangeSession.Save(person);
_visit1Id = arrangeSession.Save(new UserEntityVisit {PersonBase = person});
_visit2Id = arrangeSession.Save(new UserEntityVisit {PersonBase = person});
arrangeSession.Flush();

tx.Commit();
}
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
session.Delete("from System.Object");

transaction.Commit();
}
}

[Test]
public async Task Join_InheritanceAsync()
{
using (var session = OpenSession())
using (session.BeginTransaction())
{
var results = (await (session
.CreateCriteria<UserEntityVisit>()
.CreateCriteria(
$"{nameof(UserEntityVisit.PersonBase)}",
"f",
SqlCommand.JoinType.LeftOuterJoin,
Restrictions.Eq("Deleted", false))
.ListAsync<UserEntityVisit>()))
.Select(x => x.Id);

Assert.That(results, Is.EquivalentTo(new[] {_visit1Id, _visit2Id,}));
}
}

[Test]
public async Task Join_Inheritance_QueryOverAsync()
{
using (var session = OpenSession())
using (session.BeginTransaction())
{
PersonBase f = null;
var results = (await (session.QueryOver<UserEntityVisit>()
.JoinAlias(
x => x.PersonBase,
() => f,
SqlCommand.JoinType.LeftOuterJoin,
Restrictions.Where(() => f.Deleted == false))
.ListAsync()))
.Select(x => x.Id);

Assert.That(results, Is.EquivalentTo(new[] {_visit1Id, _visit2Id,}));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System.Linq;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Criterion;
using NHibernate.Mapping.ByCode;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH2330
{
[TestFixture]
public class JoinedSubclassWithClauseFixture : TestCaseMappingByCode
{
private object _visit1Id;
private object _visit2Id;

protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();

mapper.Class<Node>(ca =>
{
ca.Id(x => x.Id, map => map.Generator(Generators.Identity));
ca.Property(x => x.Deleted);
ca.Property(x => x.FamilyName);
ca.Table("Node");
ca.Abstract(true);
});

mapper.JoinedSubclass<PersonBase>(
ca =>
{
ca.Key(x => x.Column("FK_Node_ID"));
ca.Extends(typeof(Node));
ca.Property(x => x.Deleted);
ca.Property(x => x.Login);
});

mapper.Class<UserEntityVisit>(
ca =>
{
ca.Id(x => x.Id, map => map.Generator(Generators.Identity));
ca.Property(x => x.Deleted);
ca.ManyToOne(x => x.PersonBase);
});

return mapper.CompileMappingForAllExplicitlyAddedEntities();
}

protected override void OnSetUp()
{
using (var arrangeSession = OpenSession())
using (var tx = arrangeSession.BeginTransaction())
{
var person = new PersonBase {Login = "dave", FamilyName = "grohl"};
arrangeSession.Save(person);
_visit1Id = arrangeSession.Save(new UserEntityVisit {PersonBase = person});
_visit2Id = arrangeSession.Save(new UserEntityVisit {PersonBase = person});
arrangeSession.Flush();

tx.Commit();
}
}

protected override void OnTearDown()
{
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
session.Delete("from System.Object");

transaction.Commit();
}
}

[Test]
public void Join_Inheritance()
{
using (var session = OpenSession())
using (session.BeginTransaction())
{
var results = session
.CreateCriteria<UserEntityVisit>()
.CreateCriteria(
$"{nameof(UserEntityVisit.PersonBase)}",
"f",
SqlCommand.JoinType.LeftOuterJoin,
Restrictions.Eq("Deleted", false))
.List<UserEntityVisit>()
.Select(x => x.Id);

Assert.That(results, Is.EquivalentTo(new[] {_visit1Id, _visit2Id,}));
}
}

[Test]
public void Join_Inheritance_QueryOver()
{
using (var session = OpenSession())
using (session.BeginTransaction())
{
PersonBase f = null;
var results = session.QueryOver<UserEntityVisit>()
.JoinAlias(
x => x.PersonBase,
() => f,
SqlCommand.JoinType.LeftOuterJoin,
Restrictions.Where(() => f.Deleted == false))
.List()
.Select(x => x.Id);

Assert.That(results, Is.EquivalentTo(new[] {_visit1Id, _visit2Id,}));
}
}
}
}
26 changes: 26 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH2330/Node.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace NHibernate.Test.NHSpecificTest.GH2330
{
public abstract class Node
{
public virtual int Id { get; set; }
public virtual bool Deleted { get; set; }
public virtual string FamilyName { get; set; }
}

[Serializable]
public class PersonBase : Node
{
public virtual string Login { get; set; }
public override bool Deleted { get; set; }
}

[Serializable]
public class UserEntityVisit
{
public virtual int Id { get; set; }
public virtual bool Deleted { get; set; }
public virtual PersonBase PersonBase { get; set; }
}
}