Linq InsertOnSubmit、DeleteOnSubmit和update不工作

Linq InsertOnSubmit、DeleteOnSubmit和update不工作,linq,insertonsubmit,Linq,Insertonsubmit,我读了几篇关于InsertOnSubmit的帖子,但都没有解决我的问题。下面是我的代码,我在BackupPlan表中手动插入了一条记录,当我运行linq时,从数据库中选择该记录,我试图在下面插入的2条新记录返回并显示在日志中,但是当我签入服务器资源管理器->数据连接->表备份计划时,只有手动插入的记录在那里,而不是新记录。我还尝试更新现有记录并删除,但没有成功,也没有得到任何异常。此外,我还添加了一个列Id并将其设置为BackupPlan表的主键,检查了db.GetChangeSet()并返回了

我读了几篇关于InsertOnSubmit的帖子,但都没有解决我的问题。下面是我的代码,我在BackupPlan表中手动插入了一条记录,当我运行linq时,从数据库中选择该记录,我试图在下面插入的2条新记录返回并显示在日志中,但是当我签入服务器资源管理器->数据连接->表备份计划时,只有手动插入的记录在那里,而不是新记录。我还尝试更新现有记录并删除,但没有成功,也没有得到任何异常。此外,我还添加了一个列Id并将其设置为BackupPlan表的主键,检查了db.GetChangeSet()并返回了两条insert语句挂起,但db.SubmitChanges()随后运行,但没有成功。你知道我错过了什么吗??:(

使用System.Data.Linq.Mapping;
名称空间存储模型
{
[表(Name=“BackupPlan”)]
公共类备份计划
{
[列(IsPrimaryKey=true,IsDbGenerated=true)]
公共int Id;
[专栏]
公共字符串名称;
[专栏]
公共字符串描述;
}
}
使用System.Data.Linq;
使用存储模型;
名称空间存储
{
公共部分类存储库:DataContext
{
公共表backupplan;
公共存储库(字符串连接):基本(连接){}
}
}
使用制度;
使用System.Data.Linq;
使用System.Linq;
使用存储模型;
使用存储。属性;
名称空间存储
{
课堂测试
{
静态void Main(字符串[]参数)
{
尝试
{                
变量设置=新设置();
var db=新存储库(settings.DatabaseConnectionString)
{Log=Console.Out,ObjectTrackingEnabled=true};
var BackupPlan 1=new BackupPlan(){Description=“这是我的第一个备份计划!”,Name=“B plan”};
db.Backupplan.InsertOnSubmit(Backupplan 1);
var BackupPlan 2=new BackupPlan(){Description=“这是我的第一个备份计划2!”,Name=“B22计划”};
db.Backupplan.InsertOnSubmit(Backupplan 2);
var t=db.GetChangeSet();//显示有2个插入挂起
db.SubmitChanges();//当我运行此方法时,我会检查我的表,但没有任何新记录
var q=来自db.backupplan中的b
选择b;
foreach(q中的var backupPlan)
{
Console.WriteLine(“\n{0}”,backupPlan.Name);
}
Console.ReadKey();
}
捕获(例外e)
{
控制台写入线(e.Message);
Console.ReadKey();
}
}
}
}

构建程序后,它会将数据库文件复制到Bin/Debug,然后写入该副本


下次构建时,它将用新副本覆盖您刚写入的数据库。将其更改为“不复制”。

是否有任何异常?这是我的配置文件,其中包含连接字符串,我希望有人能提供帮助,但:(
using System.Data.Linq.Mapping;

namespace Storage.Models
{
    [Table(Name = "BackupPlan")]
    public class BackupPlan
    {
        [Column(IsPrimaryKey = true, IsDbGenerated = true)]
        public int Id;

        [Column]
        public string Name;

        [Column]
        public string Description;
    }
}

using System.Data.Linq;
using Storage.Models;

namespace Storage
{
    public partial class Repository : DataContext
    {
        public Table<BackupPlan> BackupPlans;
        public Repository(string connection):base(connection){}
    }
}

using System;
using System.Data.Linq;
using System.Linq;
using Storage.Models;
using Storage.Properties;

namespace Storage
{
    class Test
    {
        static void Main(string[] args)
        {
            try
            {                
                var settings = new Settings();
                var db = new Repository(settings.DatabaseConnectionString)
                             {Log = Console.Out, ObjectTrackingEnabled = true};                


                var backupPlan1 = new BackupPlan() {Description = "This is my first backup plan!", Name = "B Plan"};                
                db.BackupPlans.InsertOnSubmit(backupPlan1);                

                var backupPlan2 = new BackupPlan() {Description = "This is my first backup plan 2!", Name = "B22 Plan"};
                db.BackupPlans.InsertOnSubmit(backupPlan2);

                var t = db.GetChangeSet(); //shows that 2 inserts are pending

                db.SubmitChanges();   // when i run this method i check my table but there are no any new records                         

                var q = from b in db.BackupPlans
                        select b;
                foreach (var backupPlan in q)
                {
                    Console.WriteLine("\n{0}", backupPlan.Name);
                }
                Console.ReadKey();              
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
            }
        }
    }
}