I created database, for my android app, witch has 16 tables. I want to use ORMlite mapping. The problem is that I didn\'t find examples where you have composite id(Multiple
ServiceStack's OrmLite by design doesn't support multiple composite primary keys. In order for your same POCOs to be useful outside of a db (e.g. NoSQL datastores, cache providers, etc) OrmLite expects a single primary key on each type, which my default is the Id property (overridable with ModelConfig class or [PrimaryKey], [Alias] attributes).
Work arounds to overcome this limitation include creating a single unique Id but include a unique constraint on the composite primary keys, e.g:
[CompositeIndex("CompositePkId1","CompositePkId2", Unique = true)]
public class Poco
{
[AutoIncrement]
public int Id { get; set; }
public int CompositePkId1 { get; set; }
public int CompositePkId2 { get; set; }
}
Or creating a pseudo column that contains combination of all primary keys, e.g:
public class Poco
{
public string Id { get { return CompositePkId1 + ":" + CompositePkId2; } }
public int CompositePkId1 { get; set; }
public int CompositePkId2 { get; set; }
}