What's the best way to access data?
I don't think OrmLite has support for SQL Server CE but there is this. Best way might be to just use SqlCeConnection within your Services.
Can I access database path from Web.config and read it in AppHost class to create IDbConnection factory?
You should be able to add the connection string to the Web.config file.
<add name="Test" connectionString="Data Source=C:\Northwind.sdf" />
If I'm correct about OrmLite not supporting SQL CE and you want IDbConnectionFactory
like syntax in your Services you could look into using DBProviderFactories.
The simplest (not the best) thing I can think of would be doing something like below.
Create a 'bare bones' factory for SqlCEConnection. This assumes you have the connection string in your Web.config file
public class SqlCeFactory
{
public SqlCeConnection OpenConnection()
{
var conn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["Test"].ToString());
try
{
conn.Open();
return conn;
}
catch (Exception ex)
{
throw ex;
}
}
}
Register it the SqlLCeFactory in your AppHost
public override void Configure(Funq.Container container)
{
container.Register<SqlCeFactory>(new SqlCeFactory());
}
Inject it into your Service(s)
public class SourceService : ServiceStack.ServiceInterface.Service
{
public SqlCeFactory DbFactory { get; set; }
public object Get(SomeRequest request)
{
using (var con = DbFactory.OpenConnection())
{
//use SqlCeConnection()
}
//more code
}
}