Skip to content

Commit c9a37eb

Browse files
committed
Added enhanced id generators to 'Mapping by code'
1 parent 6436bf0 commit c9a37eb

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/NHibernate.Test/MappingByCode/MappersTests/IdMapperTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ public void CanSetGeneratorAssigned()
9898
hbmId.generator.@class.Should().Be.EqualTo("assigned");
9999
}
100100

101+
[Test]
102+
public void CanSetGeneratorEnhancedSequence()
103+
{
104+
var hbmId = new HbmId();
105+
new IdMapper(hbmId).Generator(Generators.EnhancedSequence);
106+
hbmId.generator.@class.Should().Be.EqualTo("enhanced-sequence");
107+
}
108+
109+
[Test]
110+
public void CanSetGeneratorEnhancedTable()
111+
{
112+
var hbmId = new HbmId();
113+
new IdMapper(hbmId).Generator(Generators.EnhancedTable);
114+
hbmId.generator.@class.Should().Be.EqualTo("enhanced-table");
115+
}
101116
private class BaseEntity
102117
{
103118
private int id;

src/NHibernate/Mapping/ByCode/Generators.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ static Generators()
1515
Sequence = new SequenceGeneratorDef();
1616
Identity = new IdentityGeneratorDef();
1717
Assigned = new AssignedGeneratorDef();
18+
EnhancedSequence = new EnhancedSequenceGeneratorDef();
19+
EnhancedTable = new EnhancedTableGeneratorDef();
1820
}
1921

2022
public static IGeneratorDef Assigned { get; private set; }
@@ -24,6 +26,8 @@ static Generators()
2426
public static IGeneratorDef GuidComb { get; private set; }
2527
public static IGeneratorDef Sequence { get; private set; }
2628
public static IGeneratorDef Identity { get; private set; }
29+
public static IGeneratorDef EnhancedSequence { get; private set; }
30+
public static IGeneratorDef EnhancedTable { get; private set; }
2731

2832
public static IGeneratorDef Foreign<TEntity>(Expression<Func<TEntity, object>> property)
2933
{
@@ -257,4 +261,56 @@ public bool SupportedAsCollectionElementId
257261
}
258262
#endregion
259263
}
264+
265+
public class EnhancedSequenceGeneratorDef : IGeneratorDef
266+
{
267+
#region Implementation of IGeneratorDef
268+
269+
public string Class
270+
{
271+
get { return "enhanced-sequence"; }
272+
}
273+
274+
public object Params
275+
{
276+
get { return null; }
277+
}
278+
279+
public System.Type DefaultReturnType
280+
{
281+
get { return typeof(int); }
282+
}
283+
284+
public bool SupportedAsCollectionElementId
285+
{
286+
get { return true; }
287+
}
288+
#endregion
289+
}
290+
291+
public class EnhancedTableGeneratorDef : IGeneratorDef
292+
{
293+
#region Implementation of IGeneratorDef
294+
295+
public string Class
296+
{
297+
get { return "enhanced-table"; }
298+
}
299+
300+
public object Params
301+
{
302+
get { return null; }
303+
}
304+
305+
public System.Type DefaultReturnType
306+
{
307+
get { return typeof(int); }
308+
}
309+
310+
public bool SupportedAsCollectionElementId
311+
{
312+
get { return true; }
313+
}
314+
#endregion
315+
}
260316
}

0 commit comments

Comments
 (0)