.
public class TwitterUser {
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
[ManyToMany(typeof(FollowerLeaderRelationshipTable), "LeaderId", "Followers",
CascadeOperations = CascadeOperation.All)]
public List<TwitterUser> FollowingUsers { get; set; }
// ReadOnly is required because we're not specifying the followers manually, but want to obtain them from database
[ManyToMany(typeof(FollowerLeaderRelationshipTable), "FollowerId", "FollowingUsers",
CascadeOperations = CascadeOperation.CascadeRead, ReadOnly = true)]
public List<TwitterUser> Followers { get; set; }
}
// Intermediate class, not used directly anywhere in the code, only in ManyToMany attributes and table creation
public class FollowerLeaderRelationshipTable {
public int LeaderId { get; set; }
public int FollowerId { get; set; }
}
관계 대신 "부모 - 자녀"의 "오빠 - 동생이"경우 예를 들어, 두 관계를 요약해야합니다 : 여기
public class Person {
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
[ManyToMany(typeof(BrothersRelationshipTable), "OldBrotherId", "YoungerBrothers",
CascadeOperations = CascadeOperation.All)]
public List<Person> OlderBrothers { get; set; }
[ManyToMany(typeof(BrothersRelationshipTable), "YoungBrotherId", "OlderBrothers",
CascadeOperations = CascadeOperation.CascadeRead, ReadOnly = true)]
public List<Brothers> YoungerBrothers { get; set; }
[Ignore]
publc List<TwitterUser> Brothers {
get { return YoungerBrothers.Concat(OlderBrothers).ToList() }
}
}
// Intermediate class, not used directly anywhere in the code, only in ManyToMany attributes and table creation
public class BrothersRelationshipTable {
public int OldBrotherId { get; set; }
public int YoungBrotherId { get; set; }
}
같은 질문을 .. 다음을 확인하십시오. http://stackoverflow.com/questions/14227468/in-sqlite-how-to-implement-a-many-to-many-relationship –