내가 개체 간의 대다 관계를 만들기 위해 SQLite는와 엔티티 프레임 워크 4.3을 사용하고 있습니다. 그러나 런타임에 Group.Parameters 및 Parameter.Groups 컬렉션은 수동으로 추가 할 때까지 비어 있습니다.EF4.3 + SQLite는 다 대다 관계
엔티티는 다음과 같습니다 OnModelCreating에서
public class Group
{
public Group()
{
Parameters = new ObservableCollection<Parameter>();
}
public Int64 Id { get; set; }
public string Name { get; set; }
public ObservableCollection<Parameter> Parameters { get; set; }
}
public class Parameter
{
public Parameter()
{
Groups = new ObservableCollection<Group>();
}
public Int64 Id { get; set; }
public string Name { get; set; }
public ObservableCollection<Group> Groups { get; set; }
}
: 작성 테이블
modelBuilder.Entity<Group>().HasMany(g => g.Parameters).WithMany(p => p.Groups).Map(c =>
{
c.MapLeftKey("GroupId");
c.MapRightKey("ParameterId");
c.ToTable("Groups_has_Parameters");
});
SQL :
create table if not exists Parameters
(
Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
Name TEXT NOT NULL
);
create table if not exists Groups
(
Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
Name TEXT NOT NULL
);
create table if not exists Groups_has_Parameters
(
GroupId INTEGER NOT NULL,
ParameterId INTEGER NOT NULL,
PRIMARY KEY (GroupId, ParameterId),
FOREIGN KEY (GroupId) REFERENCES Groups(Id),
FOREIGN KEY (ParameterId) REFERENCES Parameters(Id)
);
나는 다른 데이터가 일하는 테이블 데이터, – Alex