Open xperiandri opened 8 years ago
Yes, see http://fsprojects.github.io/SQLProvider/ for more info. The major difference is the types are erased not generated.
I can't understand how to achieve what I want. I want to return some data from DB from ASP.NET WebAPI. If I return items from table they appear to be SqlEntity not a generated type. And I don't want to specify columns one by one and return Tuple.
Because providing type safe access to columns of entity is good for F# code but not interopability.
Sorry, missed your replies to this.
So I guess you want to serialize the result directly from a call to the type provider?
This isn't possible as the types that are provided by the type provider are erased at run-time. This essentially means that all of the metadata infrastructure that most serializers require is not available.
However we have a work around by using the MapTo method on SqlEntity, see. here for an example, this simply works by matching properties on a name basis, but it is possible to override how this gets assigned.
If you do this:
let itms = query { ... } |> Seq.toArray //array of entities
let res = itms |> Array.map(fun i -> i.ColumnValues |> Map.ofSeq)
...and now you have quite nice array of maps that should be fairy simple to transfer to JSON (actually I think Newtonsoft can already serialize F#-map to JSON automatically).
Will this provider behave similar to Entity Framework and generate types for database structure?