Last active
August 29, 2015 14:17
-
-
Save atraver/13cf84e51c351c94d94b to your computer and use it in GitHub Desktop.
ServiceStack OrmLite exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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