F# - Which ORM to choose?
I've just started playing with F#, and was wondering whether there is any recommended OR开发者_高级运维M's out there, for F#.
In C# I used NHibernate, which seems to be quite hard and ugly to implement in F#. I've also thought about using plain old System.Data.SqlClient
, but thats like going back to the stone age...
Any suggestions?
I've been using F# support for LINQ to SQL when working on fssnip.net. It is fine when you need to load, edit, insert entities and it is fine for writing simple queries. It has some nice aspects e.g. you can use splicing to compose parts of a query.
However, the current implementation of F# to LINQ translator doesn't handle complex queries (nested function calls, advanced grouping and joins), so I wrote a few stored procedures. These can be nicely called via generated LINQ objects, but you have to write some SQL.
Alternatively, if you wanted to use the old fashioned SqlClient
, you could make it nicer by using the dynamic (?
) operator. I wrote about this in this blog post. For simple scenarios, this could be quite good technique, because it is very simple.
This may be missing the point (like if this is just for education or fun), but if you already know how to use an ORM in C#, why not just do it in C# as a library and then do the rest of the logic in F#? One of the major selling points for .NET languages is interoperability.
I've been using LINQ to SQL via the F# PowerPack. I'm using manual mapping (ie. creating my datacontext by hand, creating my POCO classes as well as writing the XML file to define my database layout). It seems to work well in F# from what I've done so far.
Two options for interacting with databases using F# that might be of use are FSharp.Data.SqlClient and SQLProvider.
精彩评论