1
1
using System ;
2
2
using FluentNHibernate . Mapping . Providers ;
3
3
using FluentNHibernate . MappingModel ;
4
+ using NHibernate . Mapping . ByCode ;
4
5
5
6
namespace FluentNHibernate . Mapping ;
6
7
7
8
public class CachePart ( Type entityType ) : ICacheMappingProvider
8
9
{
9
- readonly AttributeStore attributes = new AttributeStore ( ) ;
10
+ readonly AttributeStore attributes = new ( ) ;
10
11
11
12
/// <summary>
12
13
/// Sets caching to read-write
13
14
/// </summary>
14
- public CachePart ReadWrite ( )
15
- {
16
- attributes . Set ( "Usage" , Layer . UserSupplied , "read-write" ) ;
17
- return this ;
18
- }
15
+ public CachePart ReadWrite ( ) => CustomUsage ( "read-write" ) ;
19
16
20
17
/// <summary>
21
18
/// Sets caching to non-strict read-write
22
19
/// </summary>
23
- public CachePart NonStrictReadWrite ( )
24
- {
25
- attributes . Set ( "Usage" , Layer . UserSupplied , "nonstrict-read-write" ) ;
26
- return this ;
27
- }
20
+ public CachePart NonStrictReadWrite ( ) => CustomUsage ( "nonstrict-read-write" ) ;
28
21
29
22
/// <summary>
30
23
/// Sets caching to read-only
31
24
/// </summary>
32
- public CachePart ReadOnly ( )
33
- {
34
- attributes . Set ( "Usage" , Layer . UserSupplied , "read-only" ) ;
35
- return this ;
36
- }
25
+ public CachePart ReadOnly ( ) => CustomUsage ( "read-only" ) ;
37
26
38
27
/// <summary>
39
28
/// Sets caching to transactional
40
29
/// </summary>
41
- public CachePart Transactional ( )
42
- {
43
- attributes . Set ( "Usage" , Layer . UserSupplied , "transactional" ) ;
44
- return this ;
45
- }
30
+ public CachePart Transactional ( ) => CustomUsage ( "transactional" ) ;
31
+
32
+ /// <summary>
33
+ /// Sets caching to never
34
+ /// </summary>
35
+ public CachePart Never ( ) => CustomUsage ( "never" ) ;
46
36
47
37
/// <summary>
48
38
/// Specifies a custom cache behaviour
@@ -68,20 +58,12 @@ public CachePart Region(string name)
68
58
/// Include all properties for caching
69
59
/// </summary>
70
60
/// <returns></returns>
71
- public CachePart IncludeAll ( )
72
- {
73
- attributes . Set ( "Include" , Layer . UserSupplied , "all" ) ;
74
- return this ;
75
- }
61
+ public CachePart IncludeAll ( ) => CustomInclude ( "all" ) ;
76
62
77
63
/// <summary>
78
64
/// Include only non-lazy properties for caching
79
65
/// </summary>
80
- public CachePart IncludeNonLazy ( )
81
- {
82
- attributes . Set ( "Include" , Layer . UserSupplied , "non-lazy" ) ;
83
- return this ;
84
- }
66
+ public CachePart IncludeNonLazy ( ) => CustomInclude ( "non-lazy" ) ;
85
67
86
68
/// <summary>
87
69
/// Specify a custom property inclusion strategy
@@ -95,11 +77,9 @@ public CachePart CustomInclude(string custom)
95
77
96
78
internal bool IsDirty => attributes . IsSpecified ( "Region" ) || attributes . IsSpecified ( "Usage" ) || attributes . IsSpecified ( "Include" ) ;
97
79
98
- CacheMapping ICacheMappingProvider . GetCacheMapping ( )
99
- {
100
- var mapping = new CacheMapping ( attributes . Clone ( ) ) ;
101
- mapping . ContainedEntityType = entityType ;
102
-
103
- return mapping ;
104
- }
80
+ CacheMapping ICacheMappingProvider . GetCacheMapping ( ) =>
81
+ new ( attributes . Clone ( ) )
82
+ {
83
+ ContainedEntityType = entityType
84
+ } ;
105
85
}
0 commit comments