Skip to content

Commit 0462791

Browse files
committed
Update nest-breaking-changes.md
Add mappings section
1 parent 0deb9a7 commit 0462791

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

docs/2.0-breaking-changes/nest-breaking-changes.md

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,65 @@ This happens in more places e.g index settings and mappings.
107107
If you are using the object initializer syntax `*Aggregator` is now `*Aggregation`
108108

109109

110-
# BITS FROM RELEASE NOTES HERE
110+
# Attribute-based mapping
111111

112-
Mapping
112+
The single `ElasticPropertyAttribute` has been broken up into individual attributes per property type.
113+
114+
For instance, the following:
115+
116+
```csharp
117+
[ElasticType(Name = "othername", IdProperty = "MyId")]
118+
public class Foo
119+
{
120+
[ElasticProperty(Type = FieldType.String)]
121+
public Guid MyId { get; set; }
122+
123+
[ElasticProperty(Type = FieldType.String)]
124+
public string Name { get; set; }
125+
126+
[ElasticProperty(Type = FieldType.String, Analyzer = "myanalyzer", TermVector = TermVectorOption.WithOffsets)]
127+
public string Description { get; set; }
128+
129+
[ElasticProperty(Type = FieldType.Date, Format = "mmmddyyyy")]
130+
public DateTime Date { get; set; }
131+
132+
[ElasticProperty(Type = FieldType.Integer, Coerce = true)]
133+
public int Number { get; set; }
134+
135+
[ElasticProperty(Type = FieldType.Nested, IncludeInParent = true)]
136+
public List<Bar> Bars { get; set; }
137+
}
138+
```
139+
140+
becomes
141+
142+
```csharp
143+
[ElasticsearchType(Name = "othername", IdProperty = "MyId")]
144+
public class Foo
145+
{
146+
[String]
147+
public Guid MyId { get; set; }
148+
149+
[String]
150+
public string Name { get; set; }
151+
152+
[String(Analyzer = "myanalyzer", TermVector = TermVectorOption.WithOffsets)]
153+
public string Description { get; set; }
154+
155+
[Date(Format = "mmddyyyy")]
156+
public DateTime Date { get; set; }
157+
158+
[Number(NumberType.Integer, Coerce = true, DocValues = true)]
159+
public int Number { get; set; }
160+
161+
[Nested(IncludeInParent = true)]
162+
public List<Bar> Bars { get; set; }
163+
}
164+
```
165+
166+
Aside from a simpler and cleaner API, this allows each attribute to only reflect the options that are available for the particular type instead of exposing options that may not be relevant (as `ElasticPropertyAttribute` did).
167+
168+
`MapFromAttributes()` has also been renamed to `AutoMap()` to better reflect that it doesn't only depend on properties being marked with attributes. It will also infer the type based on the CLR type if no attribute is present.
113169

114170
#Renamed Types
115171

@@ -3045,4 +3101,4 @@ class VerifyRepositoryResponse
30453101
- prop: ConnectionStatus
30463102
+ prop: ApiCall
30473103
- prop: Infer
3048-
```
3104+
```

0 commit comments

Comments
 (0)