我的问题是,如果我想创建两个在这两个表之间具有[OneToMany]关系的表。
public class Order : BusinessEntity
{
[PrimaryKey]
public Guid Id{ get; set; }
[MaxLength(20)]
public string Title{ get; set;}
[MaxLength(20)]
public string Location{ get; set; }
public DateTime OrderGenerated{ get; set; }
[OneToMany(CascadeOperations=CascadeOperation.All)]
public List<OrderPos> Positions{ get; set; }
}
[Table("OrderPos")]
public class OrderPos : BusinessEntity
{
[PrimaryKey]
public Guid Id{ get; set; }
[ForeignKey(typeof(Order)), ManyToOne]
public Guid OrderId{ get; set; }
[MaxLength(20)]
public string MaterialNr{ get; set; }
[MaxLength(10)]
public string State{ get; set; }
public int Amount{ get; set; }
}表OrderPos是在没有外键的情况下创建的,因此我在InsertOrUpdateAllWithChildren方法中得到了一个异常。
我是否应该使用SqliteConnection的另一个派生类
致以最好的问候,托马斯
发布于 2015-06-20 00:40:56
您不需要在外部ket中使用ManyToOne属性,只有当您想要加载反向关系时才会使用它,即Order对象。
替换为:
[ForeignKey(typeof(Order)), ManyToOne]
public Guid OrderId{ get; set; }有了这个:
[ForeignKey(typeof(Order))]
public Guid OrderId{ get; set; }另外,我不认为Sqlite支持Guids (否则它会被当作文本处理,性能会很差),试着使用int和AutoIncrement。
除此之外,它看起来很好。
https://stackoverflow.com/questions/29005786
复制相似问题