0

我一直在网上翻找,但没有找到加快在 WindowsPhone 模拟器上创建我的数据库的解决方案。我的问题是:有没有办法加快遵循多对多关系的速度?为了创建数据库,我必须SimilarCollection为每个数据库添加一个列表,Word并在每个数据库中添加一些WordJunctionSimilar应该存储对某个 Word 的引用的列表。这令人沮丧而且非常复杂。有更好的解决方案吗?

(只有SimilarCollectionWordJunctionSimilar代码很重要)

[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>();
    }

}
4

1 回答 1

0

加快数据库创建的最佳方法 - 不要创建数据库。而是分发完整的 .SDF 文件:在您的 XAP 中,和/或在可从 Web 下载的 GZip 存档中。

通常,与模拟器相比,WP7 硬件设备的工作速度要慢得多。如果您的数据库在模拟器上那么慢,那么它可能在物理设备上完全无法使用。

我想补充一点,关系数据库(例如 SQLCE)不是灵丹妙药:有时,其他数据结构的性能可能更高,甚至可以提高几个数量级。这适用于内存数据和存储格式。

于 2013-09-13T00:28:23.580 回答