【发布时间】:2019-02-27 08:28:23
【问题描述】:
我正在尝试 xamarin 应用程序...我需要 sqlite 数据库...包含 3 个表...用户、帐户和事务...帐户表似乎:
[Table(nameof(Account))]
class Account
{
[PrimaryKey,AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
[ForeignKey(typeof(User))]
public int UserId { get; set; }
public double Balance { get; set; }
[ManyToOne]
public User User { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<Transaction> Transactions { get; set; }
}
我认为到这里为止没有问题...
但在事务表中有两列,FirstAccountId 和 TargetAccountId,所以我喜欢这样:
[Table(nameof(Transaction))]
class Transaction
{
[PrimaryKey,AutoIncrement]
public int Id { get; set; }
[ForeignKey(typeof(Account))]
public int TargetAccountId { set; get; }
[ForeignKey(typeof(Account))]
public int FirstAccountId { get; set; }
public DateTime DateOfTransaction { get; set; }
[ManyToOne()]
public Account Account1 { get; set; }
[ManyToOne()]
public Account Account2 { get; set; }`
}
如何使Account1 是FirstAccountId 的帐户,Account2 是TargetAccountId 的帐户
【问题讨论】:
标签: sqlite xamarin.forms sqlite-net-extensions