Skip to content

Commit c336aed

Browse files
committed
NH-3684 - Remove obsolete <Time>Part extension methods of QueryOver
1 parent 62cf61f commit c336aed

File tree

4 files changed

+3
-199
lines changed

4 files changed

+3
-199
lines changed

src/NHibernate.Test/Criteria/Lambda/FunctionsIntegrationFixture.cs

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,9 @@ namespace NHibernate.Test.Criteria.Lambda
88
[TestFixture]
99
public class FunctionsIntegrationFixture : TestCase
1010
{
11-
protected override string MappingsAssembly
12-
{
13-
get { return "NHibernate.Test"; }
14-
}
11+
protected override string MappingsAssembly => "NHibernate.Test";
1512

16-
protected override IList Mappings
17-
{
18-
get { return new[] { "Criteria.Lambda.Mappings.hbm.xml" }; }
19-
}
13+
protected override IList Mappings => new[] { "Criteria.Lambda.Mappings.hbm.xml" };
2014

2115
protected override void OnTearDown()
2216
{
@@ -41,69 +35,6 @@ protected override void OnSetUp()
4135
}
4236
}
4337

44-
[Test]
45-
public void YearPartEqual()
46-
{
47-
using (var s = OpenSession())
48-
using (s.BeginTransaction())
49-
{
50-
var persons = s.QueryOver<Person>()
51-
.Where(p => p.BirthDate.YearPart() == 2008)
52-
.List();
53-
54-
Assert.That(persons.Count, Is.EqualTo(1));
55-
Assert.That(persons[0].Name, Is.EqualTo("p2"));
56-
}
57-
}
58-
59-
[Test]
60-
public void YearPartIsIn()
61-
{
62-
using (var s = OpenSession())
63-
using (s.BeginTransaction())
64-
{
65-
var persons = s.QueryOver<Person>()
66-
.Where(p => p.BirthDate.YearPart().IsIn(new[] { 2008, 2009 }))
67-
.OrderBy(p => p.Name).Asc
68-
.List();
69-
70-
Assert.That(persons.Count, Is.EqualTo(2));
71-
Assert.That(persons[0].Name, Is.EqualTo("p1"));
72-
Assert.That(persons[1].Name, Is.EqualTo("p2"));
73-
}
74-
}
75-
76-
[Test]
77-
public void YearPartSingleOrDefault()
78-
{
79-
using (var s = OpenSession())
80-
using (s.BeginTransaction())
81-
{
82-
var yearOfBirth = s.QueryOver<Person>()
83-
.Where(p => p.Name == "p2")
84-
.Select(p => p.BirthDate.YearPart())
85-
.SingleOrDefault<object>();
86-
87-
Assert.That(yearOfBirth.GetType(), Is.EqualTo(typeof (int)));
88-
Assert.That(yearOfBirth, Is.EqualTo(2008));
89-
}
90-
}
91-
92-
[Test]
93-
public void SelectAvgYearPart()
94-
{
95-
using (var s = OpenSession())
96-
using (s.BeginTransaction())
97-
{
98-
var avgYear = s.QueryOver<Person>()
99-
.SelectList(list => list.SelectAvg(p => p.BirthDate.YearPart()))
100-
.SingleOrDefault<object>();
101-
102-
Assert.That(avgYear.GetType(), Is.EqualTo(typeof (double)));
103-
Assert.That(string.Format("{0:0}", avgYear), Is.EqualTo("2008"));
104-
}
105-
}
106-
10738
[Test]
10839
public void SqrtSingleOrDefault()
10940
{
@@ -216,38 +147,6 @@ public void Concat()
216147
}
217148
}
218149

219-
[Test]
220-
public void MonthPartEqualsDayPart()
221-
{
222-
using (var s = OpenSession())
223-
using (s.BeginTransaction())
224-
{
225-
var persons = s.QueryOver<Person>()
226-
.Where(p => p.BirthDate.MonthPart() == p.BirthDate.DayPart())
227-
.List();
228-
229-
Assert.That(persons.Count, Is.EqualTo(1));
230-
Assert.That(persons[0].Name, Is.EqualTo("p2"));
231-
}
232-
}
233-
234-
[Test]
235-
public void OrderByYearPart()
236-
{
237-
using (var s = OpenSession())
238-
using (s.BeginTransaction())
239-
{
240-
var persons = s.QueryOver<Person>()
241-
.OrderBy(p => p.BirthDate.YearPart()).Desc
242-
.List();
243-
244-
Assert.That(persons.Count, Is.EqualTo(3));
245-
Assert.That(persons[0].Name, Is.EqualTo("p1"));
246-
Assert.That(persons[1].Name, Is.EqualTo("p2"));
247-
Assert.That(persons[2].Name, Is.EqualTo("pP3"));
248-
}
249-
}
250-
251150
[Test]
252151
public void YearEqual()
253152
{

src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -754,21 +754,6 @@ public void OrderBy()
754754
AssertCriteriaAreEqual(expected, actual);
755755
}
756756

757-
[Test]
758-
public void OrderByYearPartFunction()
759-
{
760-
ICriteria expected =
761-
CreateTestCriteria(typeof(Person), "personAlias")
762-
.AddOrder(Order.Desc(Projections.SqlFunction("year", NHibernateUtil.Int32, Projections.Property("personAlias.BirthDate"))));
763-
764-
Person personAlias = null;
765-
IQueryOver<Person> actual =
766-
CreateTestQueryOver<Person>(() => personAlias)
767-
.OrderBy(() => personAlias.BirthDate.YearPart()).Desc;
768-
769-
AssertCriteriaAreEqual(expected, actual);
770-
}
771-
772757
[Test]
773758
public void OrderByYearFunction()
774759
{

src/NHibernate/Criterion/ProjectionsExtensions.cs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,18 @@ public static IProjection WithAlias(this IProjection projection,
2121
return Projections.Alias(projection, aliasContainer);
2222
}
2323

24-
/// <summary>
25-
/// Project SQL function year()
26-
/// Note: throws an exception outside of a QueryOver expression
27-
/// </summary>
28-
[Obsolete("Please use DateTime.Year property instead")]
29-
public static int YearPart(this DateTime dateTimeProperty)
30-
{
31-
throw new Exception("Not to be used directly - use inside QueryOver expression");
32-
}
33-
3424
internal static IProjection ProcessYear(System.Linq.Expressions.Expression expression)
3525
{
3626
IProjection property = ExpressionProcessor.FindMemberProjection(expression).AsProjection();
3727
return Projections.SqlFunction("year", NHibernateUtil.Int32, property);
3828
}
3929

40-
/// <summary>
41-
/// Project SQL function day()
42-
/// Note: throws an exception outside of a QueryOver expression
43-
/// </summary>
44-
[Obsolete("Please use DateTime.Day property instead")]
45-
public static int DayPart(this DateTime dateTimeProperty)
46-
{
47-
throw new Exception("Not to be used directly - use inside QueryOver expression");
48-
}
49-
5030
internal static IProjection ProcessDay(System.Linq.Expressions.Expression expression)
5131
{
5232
IProjection property = ExpressionProcessor.FindMemberProjection(expression).AsProjection();
5333
return Projections.SqlFunction("day", NHibernateUtil.Int32, property);
5434
}
5535

56-
/// <summary>
57-
/// Project SQL function month()
58-
/// Note: throws an exception outside of a QueryOver expression
59-
/// </summary>
60-
[Obsolete("Please use DateTime.Month property instead")]
61-
public static int MonthPart(this DateTime dateTimeProperty)
62-
{
63-
throw new Exception("Not to be used directly - use inside QueryOver expression");
64-
}
65-
6636
internal static IProjection ProcessMonth(System.Linq.Expressions.Expression expression)
6737
{
6838
return SqlFunction("month", NHibernateUtil.Int32, expression);
@@ -74,61 +44,21 @@ private static IProjection SqlFunction(string name, IType type, System.Linq.Expr
7444
return Projections.SqlFunction(name, type, property);
7545
}
7646

77-
/// <summary>
78-
/// Project SQL function hour()
79-
/// Note: throws an exception outside of a QueryOver expression
80-
/// </summary>
81-
[Obsolete("Please use DateTime.Hour property instead")]
82-
public static int HourPart(this DateTime dateTimeProperty)
83-
{
84-
throw new Exception("Not to be used directly - use inside QueryOver expression");
85-
}
86-
8747
internal static IProjection ProcessHour(System.Linq.Expressions.Expression expression)
8848
{
8949
return SqlFunction("hour", NHibernateUtil.Int32, expression);
9050
}
9151

92-
/// <summary>
93-
/// Project SQL function minute()
94-
/// Note: throws an exception outside of a QueryOver expression
95-
/// </summary>
96-
[Obsolete("Please use DateTime.Minute property instead")]
97-
public static int MinutePart(this DateTime dateTimeProperty)
98-
{
99-
throw new Exception("Not to be used directly - use inside QueryOver expression");
100-
}
101-
10252
internal static IProjection ProcessMinute(System.Linq.Expressions.Expression expression)
10353
{
10454
return SqlFunction("minute", NHibernateUtil.Int32, expression);
10555
}
10656

107-
/// <summary>
108-
/// Project SQL function second()
109-
/// Note: throws an exception outside of a QueryOver expression
110-
/// </summary>
111-
[Obsolete("Please use DateTime.Second property instead")]
112-
public static int SecondPart(this DateTime dateTimeProperty)
113-
{
114-
throw new Exception("Not to be used directly - use inside QueryOver expression");
115-
}
116-
11757
internal static IProjection ProcessSecond(System.Linq.Expressions.Expression expression)
11858
{
11959
return SqlFunction("second", NHibernateUtil.Int32, expression);
12060
}
12161

122-
/// <summary>
123-
/// Project SQL function date()
124-
/// Note: throws an exception outside of a QueryOver expression
125-
/// </summary>
126-
[Obsolete("Please use DateTime.Date property instead")]
127-
public static DateTime DatePart(this DateTime dateTimeProperty)
128-
{
129-
throw new Exception("Not to be used directly - use inside QueryOver expression");
130-
}
131-
13262
internal static IProjection ProcessDate(System.Linq.Expressions.Expression expression)
13363
{
13464
return SqlFunction("date", NHibernateUtil.Date, expression);

src/NHibernate/Impl/ExpressionProcessor.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,7 @@ static ExpressionProcessor()
174174
RegisterCustomProjection(() => default(DateTimeOffset).Second, e => ProjectionsExtensions.ProcessSecond(e.Expression));
175175
RegisterCustomProjection(() => default(DateTimeOffset).Date, e => ProjectionsExtensions.ProcessDate(e.Expression));
176176

177-
#pragma warning disable 618
178-
RegisterCustomProjection(() => ProjectionsExtensions.YearPart(default(DateTime)), e => ProjectionsExtensions.ProcessYear(e.Arguments[0]));
179-
RegisterCustomProjection(() => ProjectionsExtensions.DayPart(default(DateTime)), e => ProjectionsExtensions.ProcessDay(e.Arguments[0]));
180-
RegisterCustomProjection(() => ProjectionsExtensions.MonthPart(default(DateTime)), e => ProjectionsExtensions.ProcessMonth(e.Arguments[0]));
181-
RegisterCustomProjection(() => ProjectionsExtensions.HourPart(default(DateTime)), e => ProjectionsExtensions.ProcessHour(e.Arguments[0]));
182-
RegisterCustomProjection(() => ProjectionsExtensions.MinutePart(default(DateTime)), e => ProjectionsExtensions.ProcessMinute(e.Arguments[0]));
183-
RegisterCustomProjection(() => ProjectionsExtensions.SecondPart(default(DateTime)), e => ProjectionsExtensions.ProcessSecond(e.Arguments[0]));
184-
RegisterCustomProjection(() => ProjectionsExtensions.DatePart(default(DateTime)), e => ProjectionsExtensions.ProcessDate(e.Arguments[0]));
185-
#pragma warning restore 618
186-
187-
RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(int)), ProjectionsExtensions.ProcessSqrt);
177+
RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(int)), ProjectionsExtensions.ProcessSqrt);
188178
RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(double)), ProjectionsExtensions.ProcessSqrt);
189179
RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(decimal)), ProjectionsExtensions.ProcessSqrt);
190180
RegisterCustomProjection(() => ProjectionsExtensions.Sqrt(default(byte)), ProjectionsExtensions.ProcessSqrt);

0 commit comments

Comments
 (0)