Hello
I have my db POCO’s like this
[Schema("Core")]
[Alias("Matter_MatterType")]
public class MatterMatterType
{
[PrimaryKey]
[Required]
public long MatterId { get; set; }
[PrimaryKey]
[Required]
public int MatterTypeId { get; set; }
[PrimaryKey]
[Required]
public int SystemId { get; set; }
}
Now while running the application and using it in my endpoints it works perfectly.
But when I have to write unit tests for it I have to drop the extra primary key attributes as @mythz you already mentioned
Multiple primary keys is not supported in OrmLite so you would not be able to create tables using OrmLite or use any of its APIs which rely on primary keys.
But to cater my needs of using those models in my testing architecture where I want to test few of my endpoints.
And I use in memory sqlite database how do I use them?
I did some search and found few ways
- Create table using raw query so we can add index on it to ensure the constraints
- Dont use primary key attribute instead use
[CompositeKey(nameof(MatterId), nameof(MatterTypeId), nameof(SystemId))]
Which way would you recommend? Because in my test setup I am creating connection like this
_container.Register<IDbConnectionFactory>(new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
using (var db = _container.Resolve<IDbConnectionFactory>().Open())
{
db.DropAndCreateTable<Core.MatterMatterType>();
}
One more way which I was using prev. was to create a Test mode where I would disable those primary key and enable them in my debug and prod