Skip to content

Instantly share code, notes, and snippets.

@atraver
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atraver/13cf84e51c351c94d94b to your computer and use it in GitHub Desktop.
Save atraver/13cf84e51c351c94d94b to your computer and use it in GitHub Desktop.
ServiceStack OrmLite exception
CREATE TABLE [dbo].[Item](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Data] [nvarchar](max) NOT NULL,
[CreatedAt] [datetime] NOT NULL,
CONSTRAINT [PK_item_1] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
using System;
using ServiceStack.DataAnnotations;
[Alias("Item")]
public class ItemData
{
[AutoIncrement]
public int Id { get; set; }
public string Data { get; set; }
public DateTime CreatedAt { get; set; }
}
public class PlayerEquipment
{
[AutoIncrement]
public string Id { get; set; }
public int PlayerId { get; set; }
[References(typeof(ItemData))]
public int ItemId { get; set; }
public int Quantity { get; set; }
public bool IsEquipped { get; set; }
[Reference]
public ItemData ItemData { get; set; }
}
CREATE TABLE [dbo].[PlayerEquipment](
[Id] [int] IDENTITY(1,1) NOT NULL,
[PlayerId] [int] NOT NULL,
[ItemId] [int] NOT NULL,
[Quantity] [smallint] NOT NULL,
[IsEquipped] [bit] NOT NULL,
CONSTRAINT [PK_PlayerEquipment] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
using System;
using System.Data;
using ServiceStack.Data;
using ServiceStack.OrmLite;
public class PlayerRepository : IDisposable
{
private IDbConnectionFactory dbFactory;
private IDbConnection db;
protected IDbConnection Db
{
get { return this.db ?? (this.db = this.dbFactory.Open()); }
}
public PlayerRepository(IDbConnectionFactory dbFactory)
{
this.dbFactory = dbFactory;
}
List<PlayerEquipment GetEquipment(int playerId)
{
return this.Db.LoadSelect<PlayerEquipment>(q => q.PlayerId == playerId); // <-- MethodMissingException
}
public void Dispose()
{
if(this.db != null)
{
this.db.Dispose();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment