Explore Enterprise Library 6 DataBase 1.3 Sqlite through FSharp

Source: Internet
Author: User
Tags connectionstrings

The Enterprise Library is used to develop common components as little as possible. Database in the process of selection is often faced with the deployment, copyright, personal preferences and many other considerations. The best way to deal with this is to add a layer of data abstraction, and then switch the enterprise process seamlessly. As my notebook runs more and more slowly, and I want to try SQLite, I use SQLite as an example.
I am using Enterprise Library 6.0 originally thought that only need simple configuration can carry on the experiment, did not expect on GitHub on the SQLite to provide on the same-class the Enterprise Library 4.1 to be available. I used the online configuration file to experiment, and sure enough, there are unsupported class hints. The original thought is not to provide the correct database typeprovider, tried many times have no results. The best way to always go wrong is to rest and look around. Sure enough, an expert has tried out on the CodeProject. I expanded the class myself, and studied later. Let's get back to the chase.
I used a test database that comes with SQLite in my configuration file. The code that queries the database by sending SQL statements has almost no change to get the desired results successfully.
Configuration file
<?xml version= "1.0"?><configuration> <configSections> <section name= "dataconfiguration" type= " Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, version=6.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35 " Requirepermission= "true"/> <section name= "connectionStrings" type= " System.Configuration.ConnectionStringsSection, System.Configuration, version=4.0.0.0, Culture=neutral, PUBLICKEYTOKEN=B03F5F7F11D50A3A "requirepermission=" true "/> </configSections> <dataconfiguration Defaultdatabase= "SSS" ><providermappings><add databasetype= "EntLibContrib.Data.SQLite.SQLiteDatabase , EntLibContrib.Data.SQLite, version=1.0.0.0, Culture=neutral, Publickeytoken=null "name=" System.Data.SQLite "/> </providerMappings> </dataConfiguration> <system.data> </system.data> <connectionst rings> <add name= "Exampledatabase" connectionString= "Data source= (localdb) \v11.0; attachdbfilename=e:\workhell\fsharp-practise\enterpriselibrarypractise\dataaccessexamples.mdf;integrated Security=true "providername=" System.Data.SqlClient "/> <add name=" asyncexampledatabase "connectionstring=" Da Ta source= (localdb) \v11.0; asynchronous processing=true; attachdbfilename=|  datadirectory|\dataaccessexamples.mdf;integrated security=true "providername=" System.Data.SqlClient "/> <add Name= "DataAccessExample.Properties.Settings.DataAccessExamplesConnectionString" connectionstring= "Data source= ( LOCALDB) \v11.0; attachdbfilename=|  datadirectory|\dataaccessexamples.mdf;integrated security=true "providername=" System.Data.SqlClient "/> <add Name= "SSS" connectionstring= "Data source=e:\workhell\fsharp-practise\enterpriselibrarypractise\dbdemos.db3;      version=3; " Providername= "System.Data.SQLite"/> </connectionStrings></configuration>

Code
#if interactive#i @ "E:\WorkHell\fsharp-practise\packages" #r @ "enterpriselibrary.data.6.0.1304.0\lib\net45\ Microsoft.Practices.EnterpriseLibrary.Data.dll "#r @" enterpriselibrary.common.6.0.1304.0\lib\net45\ Microsoft.Practices.EnterpriseLibrary.Common.dll "#r @" system.data.sqlite.core.1.0.94.0\lib\net45\ System.Data.SQLite.dll "#r @" EntLibContrib.Data.SQLite.dll "#r" System "#r" System.Data "#r" System.Configuration "# Endifopen Systemopen System.dataopen System.Data.Commonopen System.Data.SqlClientopen Microsoft.Practices.EnterpriseLibrary.Dataopen Microsoft.Practices.EnterpriseLibrary.Common.Configurationopen Microsoft.Practices.EnterpriseLibrary.Data.Sqlopen Microsoft.Practices.EnterpriseLibrary.Data.Configurationopen System.threadingopen System.Threading.Tasksopen System.configurationopen System.Data.SQLiteopen EntLibContrib.Data.SQLitelet Displayrowvalue (Reader:idatareader) = while reader. Read () does for i = 0 to reader. FieldCount-1 do Console.WriteLine ("{0}={1}", Reader. GetName (i), reader. [i]. ToString ()) Console.WriteLine () Let Path = __source_directory__ + "\fsiapp.config" let Filemap = Configurationfilemap (Pat h) Let config = configurationmanager.openmappedmachineconfiguration (filemap) Let factory = new Databaseproviderfactory ( Fun S-config. GetSection (s)) Let Defaultdb = Factory. Create ("SSS") Let reader = Defaultdb.executereader (CommandType.Text, "select * from Orders") Displayrowvalue Reader

Above

Explore Enterprise Library 6 DataBase 1.3 Sqlite through FSharp

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.