TL;DR
- レコード型は、各フィールドを DTO の型に変換したレコードで表現する。
内容
ドメイン型を DTO に変換する方法の 1 つである。レコード型は、各フィールドを DTO 用の型に変換したレコードで表現する。たとえば、次のドメインの型を考える。
type OrderLineId = OrderLineId of int
type OrderLineQty = OrderLineQty of int
type OrderLine =
{ OrderLineId: OrderLineId
ProductCode: ProductCode
Quantity: OrderLineQty option
Description: string option }単純型はプリミティブ型に、値型のオプションは Nullable に、参照型のオプションはそのままの型にする。DTO は次のようになる。
type OrderLineDto =
{ OrderLineId: int
ProductCode: string
Quantity: Nullable<int>
Description: string }フィールドごとの変換方法は、単純型を DTO に変換するとオプション型を DTO に変換するに書いた。