SQL data access

In F#, there are multiple libraries for SQL data access. We can browse them in NuGet; a few of them are discussed as follows:

  • FSharp.Data.SqlClient: This library provides SqlCommandProvider, which gives type safe access to transactional SQL languages. SqlProgrammabilityProvider provides quick access to a SQL server stored procedure (SP), tables, and functions, and SqlEnumProvider generates an enum type on the ground of static lookup data from an ADO.NET-compliant source.
    To install the FSharp.Data.SqlClient library from NuGet, use the following command:
PM> Install-Package FSharp.Data.SqlClient
  • FSharp.Data.SQLProvider: SQLProvider is a general .NET/Mono SQL database provider. This library supports automatic constraint navigation, CRUD operations with identity support, asynchronous operations, LINQ query, functions, SP support, record types mapping, .NET Core/.NET Standard, and so on. SQLProvider has explicit implementation for SQL Server, SQLite, Oracle, MySQL, MSAccess, Firebird, and so on. SQL Server and MS Access don't require third-party ADO.NET connector objects, the rest all require this.
    To install the FSharp.Data.SqlProvider library from NuGet, use the following command:
PM> Install-Package SQLProvider
  • The SqlDataConnection: SqlDataConnection type provider generates types, for data in SQL DB on live connections. It is for accessing SQL using LINQ queries. It requires a Microsoft SQL server. We need three references in a F# project—FSharp.Data.TypeProviders, System.Data, and System.Data.Linq. Here is an example:
type dbSchemaExample = SqlDataConnection<"Data Source=SERVERINSTANCENAME;Initial Catalog=MyDatabase;Integrated Security=SSPI;">

let db = dbSchemaExample.GetDataContext()
  • The SqlEntityConnection: SqlEntityConnection type provider is for accessing SQL through LINQ queries and Entity Framework. It works with many databases. We need System.Data.Linq, System.Data.Entity, and Microsoft.FSharp.Data.TypeProviders references. Here is an example:
type private EntityConnectionExample = SqlEntityConnection<ConnectionString="Server=SERVERInstanceName;Initial Catalog=microsoft;Integrated Security=SSPI;MultipleActiveResultSets=true",Pluralize = true>
  • ADO.NET: It provides data access services and functionality for writing managed code and consistent data source access for SQL Server, and also data sources exposed through OLEDB or XML. Customers can use ADO.NET to connect with any data source to retrieve, manipulate, and update data. It can perform all CRUD operations. ADO.NET also supports frontend database creation, and middle-tier objects for application, tools, or browsers.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset