标签:enterprise library f# fsharp sql sqlite
使用Enterprise Library就是为了尽可能少的开发常用组件。数据库在选择的过程中常会面临部署,版权,个人喜好等诸多考量。最佳的处理方法就是添加一层数据抽象层,再切换Enterprise的过程中进行无缝衔接。由于我的笔记本跑的越来越慢,又想尝试一下使用Sqlite所以,就用Sqlite做例子。<?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> <connectionStrings> <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="Data 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>
#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" #endif open System open System.Data open System.Data.Common open System.Data.SqlClient open Microsoft.Practices.EnterpriseLibrary.Data open Microsoft.Practices.EnterpriseLibrary.Common.Configuration open Microsoft.Practices.EnterpriseLibrary.Data.Sql open Microsoft.Practices.EnterpriseLibrary.Data.Configuration open System.Threading open System.Threading.Tasks open System.Configuration open System.Data.SQLite open EntLibContrib.Data.SQLite let DisplayRowValue (reader:IDataReader) = while reader.Read() do 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(path) 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
通过fsharp探索Enterprise Library 6 DataBase 1.3 Sqlite
标签:enterprise library f# fsharp sql sqlite
原文地址:http://blog.csdn.net/samwell/article/details/41082813