繁体   English   中英

WP7后台代理数据库访问

[英]WP7 background agent database access

我是C#的初级程序员,所以我认为我的问题的解决方法可能很简单,但是在寻找了好几天之后,我仍然没有找到适合我的方法。

我有一个WP7应用程序,其中包含使用SQL CE创建的数据库。

类PorniBD.cs

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Data.Linq.Mapping;

namespace PhoneClassLibrary1
{
    [Table(Name = "Papilleros")]
    public class PorniBD
    {
        [Column(IsPrimaryKey = true, IsDbGenerated = true)]
        public int Id { get; set; }
        [Column(CanBeNull = false)]
        public String Nombre { get; set; }
        [Column(CanBeNull = false)]
        public String FechaNac { get; set; }
        [Column(CanBeNull = false)]
        public Boolean Activo { get; set; }
        [Column(CanBeNull = false)]
        public String Icono { get; set; }
    }
}

类PorniContext.cs

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Data.Linq.Mapping;
using System.Data.Linq;

namespace PhoneClassLibrary1
{
    public class PorniContext : DataContext
    {
        public PorniContext(string connectionString) : base(connectionString)
        {
            //
        }

        public Table<PorniBD> Papilleros
        {
            get
            {
                return this.GetTable<PorniBD>();
            }
        }
    }
}

我的应用程序在另一个项目中创建了后台代理,就像我在此页面中所学到的: 链接

现在,我需要从后台代理读取应用程序数据库,并且此类包含以下OnInvoke void:

protected override void OnInvoke(ScheduledTask task)
        {
            List<PorniBD> listapapilleros = new List<PorniBD>();
            using (PorniContext basedatos = new PorniContext("Data Source='isostore:/basedatos.sdf'"))
            {
                listapornis = basedatos.Papilleros.ToList();
            }

            // Launch a toast to show that the agent is running.
            // The toast will not be shown if the foreground application is running.

            ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(10));
            NotifyComplete();
        }

但是这是不可能的,因为每个项目中隔离的数据源都是不同的(我认为),而且我认为有必要修复更多问题……

非常感谢您的帮助,对于我的英语水平让我的解释有点难以理解感到抱歉...

只需创建“ Windows Phone类库”类型的第三个项目。 在第三个项目中移动数据库代码,然后从主项目和后台代理项目中引用它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM