3

如何阻止 ServiceStack.Net OrmLite 自动生成主键列?

我的模型如下:

public class Flower2Bee
{
    public int FlowerId { get; set; }
    public int BeeId { get; set; }
}

当我运行 db.CreateTable(true, typeof(Flower2Bee)) 时,它为 FlowerId col 提供了一个具有唯一约束的主键索引。

由于上述模型旨在促进多对多关系,这提出了一个明显的问题。我也注意到这发生在其他不打算有主键的表上。

我的偏好是关闭此行为,因为我很乐意在需要的地方显式定义具有属性的主键。

我正在使用 OrmLite 和 Sqlite,以防万一这很重要。

4

1 回答 1

4

This is a known limitation of ServiceStack.Net OrmLite:

https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/README.md#limitations

All tables must have a primary key in order to maintain compatibility with certain peristance technologies. The solution for the above question is to add a third Id property to the model to serve as the primary Id of each relationship row.

于 2013-03-30T09:53:13.770 回答