我一直在网上翻找,但没有找到加快在 WindowsPhone 模拟器上创建我的数据库的解决方案。我的问题是:有没有办法加快遵循多对多关系的速度?为了创建数据库,我必须SimilarCollection
为每个数据库添加一个列表,Word
并在每个数据库中添加一些WordJunctionSimilar
应该存储对某个 Word 的引用的列表。这令人沮丧而且非常复杂。有更好的解决方案吗?
(只有SimilarCollection
和WordJunctionSimilar
代码很重要)
[Table]
public class Word
{
[Table]
public class SimilarCollection
{
[Column(IsPrimaryKey = true)]
public int SimilarId { get; set; }
[Column]
public string Translation { get; set; }
[Column]
public int? WordId { get; set; }
private EntitySet<WordJunctionSimilar> junction;
[Association(Name = "FK_Similar_Words1", Storage = "junction", ThisKey = "SimilarId", OtherKey = "SimilarId")]
public EntitySet<WordJunctionSimilar> Junction
{
get { return junction; }
set { junction = value; }
}
public SimilarCollection()
{
Junction = new EntitySet<WordJunctionSimilar>((w) => w.SimilarId = this.SimilarId,(w) => w.SimilarId = 0);
}
}
[Column(IsPrimaryKey = true)]
public int WordId { get; set; }
[Column(CanBeNull = false)]
public string Foreign { get; set; }
[Column]
public string Conjugation { get; set; }
[Column]
public string SpeechPart { get; set; }
[Column]
public string Type { get; set; }
private EntitySet<SimilarCollection> similar;
[Association(Name = "FK_Words_Similar", ThisKey = "WordId", OtherKey = "WordId", Storage = "similar")]
public EntitySet<SimilarCollection> Similar
{
get { return similar; }
set { similar = value; }
}
public Word()
{
Conjugation = "";
SpeechPart = "";
Type = "";
Similar = new EntitySet<SimilarCollection>(OnSimilarAdded,OnSimilarRemoved);
}
private void OnSimilarAdded(SimilarCollection similar)
{
similar.WordId = this.WordId;
}
private void OnSimilarRemoved(SimilarCollection similar)
{
similar.WordId = null;
}
}
[Table]
public class WordJunctionSimilar
{
[Column(IsPrimaryKey=true)]
public int WordId;
[Column(IsPrimaryKey=true)]
public int SimilarId;
private EntityRef<Word> wordRef;
[Association(Name="FK_Similar_Words0", Storage="wordRef",ThisKey="WordId",OtherKey="WordId")]
public Word WordRef
{
get { return wordRef.Entity; }
set { wordRef.Entity = value; WordId = value.WordId; }
}
public WordJunctionSimilar()
{
wordRef = new EntityRef<Word>();
}
}