0

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

但这是不可能的,因为每个项目中隔离的 DataSource 都不同(我认为),我认为有必要修复更多的东西......

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

4

1 回答 1

1

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

于 2013-08-28T08:09:43.563 回答