fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
570 stars 144 forks source link

Can I use MapTo on a record with a child collection? #640

Closed JordanMarr closed 4 years ago

JordanMarr commented 4 years ago

Question

Is it possible to use MapTo<Order>() if I have a record type with a one-to-many relationship? So far it looks like I would have to manually instantiate the record.

Ex:

type Order = {
  Id: int  
  OrderItems: OrderItem array
}
and OrderItem = {
  Id: int
  Desc: string
}
Thorium commented 4 years ago

I would like to see some examples how people use MapTo in real life, as there are no unit tests and I don't use it.

Thorium commented 4 years ago

MapTo is dealing with propertyname-to-obj maps, so it would be quite simple to add a small recursion to this.

Thorium commented 4 years ago

Update, yes you can, if you provide the mapping parameter function to MapTo-method. See https://github.com/fsprojects/SQLProvider/issues/666#issuecomment-581812959