为什么我的LINQ中插入未在SQL Server CE 3.5坚持? [英] Why are my LINQ INSERTS not persisting in SQL Server CE 3.5?

查看:202
本文介绍了为什么我的LINQ中插入未在SQL Server CE 3.5坚持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用LINQ与SQL Server Compact 3.5版和VS2008为SQL。

I am using LINQ to SQL with Sql Server Compact Edition 3.5 and VS2008.

我有一个非常简单的表(令牌)与唯一标识符的主键(TokenID)和另外两个可为空字段(UsedBy和UsedOn)。 。我试图使用LINQ插入新行插入表中,但出于某种原因,他们没有坚持

I have a very simple table (Tokens) with a uniqueidentifier primary key (TokenID) and two other nullable fields (UsedBy and UsedOn). I am trying to use LINQ to insert new rows into the table but for some reason they are not persisting.

下面是我的代码:

    	var connectionstring = "Data Source=|DataDirectory|\\MyData.sdf";
		MyData db = new MyData(connectionstring) { Log = Console.Out };

		Tokens token = new Tokens { TokenID = Guid.NewGuid() };
		db.Tokens.InsertOnSubmit(token);
		//db.GetChangeSet();
		db.SubmitChanges();

		var tokens = from t in db.Tokens
					 select t;
		foreach (var t in tokens)
		{
			Debug.Print(t.TokenID.ToString());
		}

如果我取消db.GetChangeSet();我可以看到挂起的插入,当我重复,并将其打印到调试寡妇令牌#每次增长。但是,如果我在查询VS表(通过显示表的数据),它是空的?查看数据这样也重新安排的LINQ返回其原始状态的标记。

If I uncomment db.GetChangeSet(); I can see the pending insert and when I iterate and print them to the debug widow the # of tokens grows each time. But if I query the table in VS (via Show Table Data) it is empty? Viewing the data like this also "resets" the tokens returned by LINQ their original state.

我敢肯定我做一些简单的错误,但我看不到它。任何想法?

I am pretty sure I am making some simple mistake, but I can't see it. Any ideas?

推荐答案

检查,在每个构建你的数据库文件不会被复制到输出目录(中的属性页项目项)

Check that your DB file is not copied to the output directory at each build (in the property page of the project item)

这篇关于为什么我的LINQ中插入未在SQL Server CE 3.5坚持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆