I have been coding with ServiceStack for a little while now, but strangely enough I've been getting this error: "Cannot insert duplicate key row in object 'dbo.Shop' with unique index
'uidx_shop_name'. The duplicate key value is (Johann's Clothing Shop).
The statement has been terminated."
Stack trace:
[ShopService: 29/04/2012 3:10:23 PM]: [REQUEST: ]System.Data.SqlClient.SqlException (0x80131904): Cannot insert duplicate key row in object 'dbo.Shop' with unique index 'uidx_shop_name'. The duplicate key value is (Johann's Clothing Shop). The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at ServiceStack.MiniProfiler.Data.ProfiledDbCommand.ExecuteNonQuery() at ServiceStack.OrmLite.OrmLiteWriteExtensions.ExecuteSql(IDbCommand dbCmd, String sql) at ServiceStack.OrmLite.OrmLiteWriteExtensions.InsertAll[T](IDbCommand dbCmd, IEnumerable`1 objs) at SocialBootstrapApi.ServiceInterface.ShopService.<Run>b__20(IDbCommand dbCmd) in c:\Users\AlecTaylor\SocialBootstrapApi\src\SocialBootstrapApi\ServiceInterface\ClothingService.cs:line 142 at ServiceStack.OrmLite.OrmLiteConnectionFactoryExtensions.Exec[T](IDbConnectionFactory connectionFactory, Func`2 runDbCommandsFn) at SocialBootstrapApi.ServiceInterface.ShopService.Run(Shop request) in c:\Users\AlecTaylor\SocialBootstrapApi\src\SocialBootstrapApi\ServiceInterface\ClothingService.cs:line 109 at ServiceStack.ServiceInterface.ServiceBase`1.Execute(TRequest request) ClientConnectionId:5bb10372-54f5-48ba-a0c5-b2a12d692dc3
The code:
http://pastebin.com/PS8SUupxI have tried to write my code as standards compliant as possible (you'll find that almost all of it is taken from ServiceStack example code), but I still might have some bad practices + bad code quality.
Please point out any of these sorts of problems as well as telling me how to fix the database problem.
Thanks,
Alec Taylor
BTW: The only unique field I want in each class is Id
FYI: I have also tried renaming the Shop names