Skip to content

Commit 0d31697

Browse files
committed
Fixing #69
1 parent 8b63349 commit 0d31697

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog for `FSharp.CosmosDb`
22

3+
## [1.2.1] - Unreleased
4+
5+
### Fixes
6+
7+
- Fixing #69 by finding a property using conventions first, before raising an error
8+
39
## [1.2.0] - 2022-08-22
410

511
### Added

src/FSharp.CosmosDb/OperationHandling.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ let getIdFieldName<'T> (item: 'T) =
1111

1212
match idAttr with
1313
| Some attr -> attr.GetValue(item).ToString()
14-
| None -> "id"
14+
| None ->
15+
let property = item.GetType().GetProperties() |> Array.tryFind(fun p -> p.Name.Equals("id", StringComparison.InvariantCultureIgnoreCase))
16+
match property with
17+
| Some property -> property.GetValue(item).ToString()
18+
| None -> failwith "Unable to determine the id field of the type. Either use the IdAttribute or have a field named Id"
1519

1620
let getPartitionKeyValue<'T> (single: 'T) =
1721
let partitionKey = PartitionKeyAttributeTools.findPartitionKey<'T> ()

0 commit comments

Comments
 (0)