Windows phone 7 Windows Phone 7上的Sterling序列化问题

Windows phone 7 Windows Phone 7上的Sterling序列化问题,windows-phone-7,sterling-db,Windows Phone 7,Sterling Db,我对用于Windows Phone的Sterling数据库有问题。我在wp7app中一步一步地实现了数据库,但在保存新实体时,它不会序列化数据。例如:我使用sterling数据库序列化凭据: var userCredentials = new UserCredentials(userName, password); App.Database.Save(userCredentials); App.Database.Flush(); 但当重新激活(或

我对用于Windows Phone的Sterling数据库有问题。我在wp7app中一步一步地实现了数据库,但在保存新实体时,它不会序列化数据。例如:我使用sterling数据库序列化凭据:

        var userCredentials = new UserCredentials(userName, password);
        App.Database.Save(userCredentials);
        App.Database.Flush();
但当重新激活(或重新启动)应用程序时,Sterling不会从独立存储返回任何值:

var firstOrDefault = App.Database.Query<UserCredentials, string>()
            .ToList()
            .FirstOrDefault();
var firstOrDefault=App.Database.Query()
托利斯先生()
.FirstOrDefault();
我的ActivateEngine方法外观是标准的,TableDefinition是:

CreateTableDefinition(t=>t.UserName),


为什么sterling数据库不序列化我的数据?一切似乎都很顺利。请提供帮助。

您是否按照中的说明在启动时激活并注册数据库,并在完成时激活并注册数据库

我个人的偏好是使用类似于以下内容的应用程序服务:

namespace MyApp.Data
{
    using System.Windows;
    using Wintellect.Sterling;
    using Wintellect.Sterling.IsolatedStorage;

    /// 
    /// Defines a an application service that supports the Sterling database.
    /// 
    public class SterlingDatabaseService : IApplicationService, IApplicationLifetimeAware
    {
        public static SterlingDatabaseService Current { get; private set; }

        public ISterlingDatabaseInstance Database { get; private set; }

        private SterlingEngine _engine;

        /// 
        /// Called by an application in order to initialize the application extension service.
        /// 
        /// Provides information about the application state.
        public void StartService(ApplicationServiceContext context)
        {
            Current = this;
            _engine = new SterlingEngine();
        }

        /// 
        /// Called by an application in order to stop the application extension service.
        /// 
        public void StopService()
        {
            _engine = null;
        }

        /// 
        /// Called by an application immediately before the  event occurs.
        /// 
        public void Starting()
        {
            _engine.Activate();
            Database = _engine
                .SterlingDatabase
                .RegisterDatabase(new IsolatedStorageDriver());
        }

        /// 
        /// Called by an application immediately after the  event occurs.
        /// 
        public void Started()
        {
            return;
        }

        /// 
        /// Called by an application immediately before the  event occurs.
        /// 
        public void Exiting()
        {
            _engine.Dispose();
        }

        /// 
        /// Called by an application immediately after the  event occurs.
        /// 
        public void Exited()
        {
            return;
        }
    }
}
如果使用这种方法,请不要忘记在App.xaml中添加一个实例:

    <Application.ApplicationLifetimeObjects>
        <!-- Required object that handles lifetime events for the application. -->
        <shell:PhoneApplicationService Activated="Application_Activated"
                                       Closing="Application_Closing"
                                       Deactivated="Application_Deactivated"
                                       Launching="Application_Launching" />
        <data:SterlingDatabaseService />
    </Application.ApplicationLifetimeObjects>

谢谢你的帖子,德里克,这对我帮助很大。我注意到,在注册datatable时,我没有指定要使用IsolatedStorageDriver。我用这行代码修复了它:
\u database=\u engine.SterlingDatabase.RegisterDatabase(新的IsolatedStorageDriver())非常感谢!