Reputation: 333
I'm trying to test out ServiceStack for an MVC 4 App in VS2012:
(PM> Install-Package ServiceStack.Host.Mvc)
However I immediately get the following 3 errors on build even after following the special instructions for MvC.
The non-generic method 'ServiceStack.ContainerTypeExtensions.Register(Funq.Container, object, System.Type)' cannot be used with type arguments
Cannot convert lambda expression to type 'ServiceStack.Data.IDbConnectionFactory' because it is not a delegate type
The name 'SqlServerDialect' does not exist in the current context
They're all related to the following code in AppHost.cs
// Requires ConnectionString configured in Web.Config
var connectionString = ConfigurationManager.ConnectionStrings["AppDb"].ConnectionString;
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(connectionString, SqlServerDialect.Provider));
Upvotes: 1
Views: 484
Reputation: 143379
That code is not being used by any of the example services so you can just comment it out, e.g:
//container.Register<IDbConnectionFactory>(c =>
// new OrmLiteConnectionFactory(connectionString, SqlServerDialect.Provider));
But if you want to use SqlServer with ServiceStack's OrmLite you can install it from NuGet:
PM> Install-Package ServiceStack.OrmLite.SqlServer
Otherwise you can install your preferred RDBMS solution, e.g. for PostgreSQL, install:
PM> Install-Package ServiceStack.OrmLite.PostgreSQL
And you would change it to use the PostgreSQL provider, e.g:
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(connectionString, PostgreSqlDialect.Provider));
You can then use the Db database inside your services or razor views like:
In your AppHost:
using (var db = container.Resolve<IDbConnectionFactory>().Open()) {
Db.CreateTableIfNotExists<TestDb>();
}
Use Db property in your ServiceStack services (or Razor Views):
public object Any(TestDb request)
{
Db.Insert(request);
return Db.SingleById<TestDb>(request.Id);
}
*TestDb can be any POCO, Request DTO, etc.
Upvotes: 2
Reputation: 686
Check to make sure the dependency packages are in your references and using'ed as necessary.
<dependency id="WebActivator" version="1.5" />
<dependency id="ServiceStack.Mvc" version="4.0" />
<dependency id="ServiceStack.Server" version="4.0" />
<dependency id="ServiceStack.OrmLite.SqlServer" version="4.0" />
List pulled from https://github.com/ServiceStack/ServiceStack/blob/master/NuGet/ServiceStack.Host.Mvc/servicestack.host.mvc.nuspec
Upvotes: 2