|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using NHibernate.Cfg.MappingSchema; |
| 4 | +using NHibernate.Criterion; |
| 5 | +using NHibernate.Mapping.ByCode; |
| 6 | +using NHibernate.SqlCommand; |
| 7 | +using NUnit.Framework; |
| 8 | + |
| 9 | +namespace NHibernate.Test.NHSpecificTest.NH1761 |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + public class ByCodeFixture : TestCaseMappingByCode |
| 13 | + { |
| 14 | + protected override HbmMapping GetMappings() |
| 15 | + { |
| 16 | + var mapper = new ModelMapper(); |
| 17 | + mapper.Class<FundingCategory>(rc => |
| 18 | + { |
| 19 | + rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); |
| 20 | + rc.Property(x => x.Name); |
| 21 | + rc.Bag(x => x.FundingPrograms, m => {}, r => r.OneToMany()); |
| 22 | + |
| 23 | + }); |
| 24 | + mapper.Class<FundingProgram>(rc => |
| 25 | + { |
| 26 | + rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); |
| 27 | + rc.ManyToOne(x => x.Recipient); |
| 28 | + rc.Property(x => x.ObligatedAmount); |
| 29 | + rc.Bag(x => x.Projects, m => { m.OrderBy("Name asc"); }, r => r.OneToMany()); |
| 30 | + }); |
| 31 | + mapper.Class<Project>(rc => |
| 32 | + { |
| 33 | + rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); |
| 34 | + rc.ManyToOne(x => x.Recipient); |
| 35 | + rc.Property(x => x.ObligatedAmount); |
| 36 | + }); |
| 37 | + mapper.Class<Recipient>(rc => |
| 38 | + { |
| 39 | + rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); |
| 40 | + }); |
| 41 | + return mapper.CompileMappingForAllExplicitlyAddedEntities(); |
| 42 | + } |
| 43 | + |
| 44 | + [Test] |
| 45 | + public void InvalidOrderByClause() |
| 46 | + { |
| 47 | + using (var session = OpenSession()) |
| 48 | + { |
| 49 | + var recipientId = Guid.NewGuid(); |
| 50 | + session.CreateCriteria(typeof(FundingCategory), "fc") |
| 51 | + .CreateCriteria("FundingPrograms", "fp") |
| 52 | + .CreateCriteria("Projects", "p", JoinType.LeftOuterJoin) |
| 53 | + .Add( |
| 54 | + Restrictions.Disjunction() |
| 55 | + .Add(Restrictions.Eq("fp.Recipient.Id", recipientId)) |
| 56 | + .Add(Restrictions.Eq("p.Recipient.Id", recipientId)) |
| 57 | + ) |
| 58 | + .SetProjection( |
| 59 | + Projections.ProjectionList() |
| 60 | + .Add(Projections.GroupProperty("fc.Name"), "fcn") |
| 61 | + .Add(Projections.Sum("fp.ObligatedAmount"), "fpo") |
| 62 | + .Add(Projections.Sum("p.ObligatedAmount"), "po") |
| 63 | + ) |
| 64 | + .AddOrder(Order.Desc("fpo")) |
| 65 | + .AddOrder(Order.Desc("po")) |
| 66 | + .AddOrder(Order.Asc("fcn")) |
| 67 | + .List<object[]>(); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + public class FundingCategory |
| 73 | + { |
| 74 | + public virtual Guid Id { get; set; } |
| 75 | + public virtual string Name { get; set; } |
| 76 | + public virtual IList<FundingProgram> FundingPrograms { get; set; } = new List<FundingProgram>(); |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + public class FundingProgram |
| 81 | + { |
| 82 | + public virtual Guid Id { get; set; } |
| 83 | + public virtual Recipient Recipient { get; set; } |
| 84 | + public virtual decimal ObligatedAmount { get; set; } |
| 85 | + public virtual IList<Project> Projects { get; set; } = new List<Project>(); |
| 86 | + } |
| 87 | + |
| 88 | + public class Project |
| 89 | + { |
| 90 | + public virtual Guid Id { get; set; } |
| 91 | + public virtual Recipient Recipient { get; set; } |
| 92 | + public virtual decimal ObligatedAmount { get; set; } |
| 93 | + } |
| 94 | + |
| 95 | + public class Recipient |
| 96 | + { |
| 97 | + public virtual Guid Id { get; set; } |
| 98 | + } |
| 99 | +} |
0 commit comments