本地数据库Windows Phone 7

时间:2012-04-01 02:14:54

标签: c# xaml windows-phone-7.1 local-database

我为我的Windows Phone 7应用创建了一个本地数据库,并使用msdn上的教程创建了一个表。我有第二个表的问题如何添加它?当我用Linq创建另一个类时,我是否需要使用相同的datacontext类并添加另一个表?我尝试了很多东西,我尝试创建它的方式与第一个表格相同,但似乎没有任何工作我的应用程序只是崩溃。请帮忙

1 个答案:

答案 0 :(得分:1)

假设程序使用一个表运行正常(因此您知道您的连接字符串和datacontext对于一个表是正常的),那么当您添加第二个表时,您需要编写一个带有[Table]属性的附加类并且您需要向datacontext添加属性。

    public class ATestDataContext : DataContext
    {
        public ATestDataContext(string connectionString) : base(connectionString)
        {
        }

        public Table<FTable> FirstTable
        {
            get
            {
                return this.GetTable<FTable>();
            }
        }

        public Table<STable> SecondTable
        {
            get
            {
                return this.GetTable<STable>();
            }
        }
    }

[Table]
public class FTable : INotifyPropertyChanged, INotifyPropertyChanging
{...}

[Table]
public class STable : INotifyPropertyChanged, INotifyPropertyChanging
{...}

如果您希望在表之间建立关系,例如master-detail,那么您的课程中还需要其他内容。我遇到的最好的例子之一是:http://windowsphonegeek.com/articles/Windows-Phone-Mango-Local-Database-mapping-and-database-operations