我想使用 LINQ 和 SQL Server CE 执行事务。
该SubmitChanges
方法似乎工作正常。但是,如果我查看数据表,则不会应用更改。
我的代码:
var query = (from s in this.tblRequirements
where s.abbrevation == "rml"
select new {s}).First();
System.Windows.Forms.MessageBox.Show("First: " + query.s.abbrevation);
query.s.abbrevation = "rmlas";
try
{
this.rdb.SubmitChanges();
}
catch (ChangeConflictException e)
{
System.Windows.Forms.MessageBox.Show(e.ToString());
}
System.Windows.Forms.MessageBox.Show("Second: " + query.s.abbrevation);
query = (from s in this.tblRequirements
where s.requirementID == 4
select new { s }).First();
System.Windows.Forms.MessageBox.Show("Third: " + query.s.abbrevation);
消息输出:
First = "rml"
Second = "rmlas"
Third = "rmlas"
我的桌子:
[requirementID] INT IDENTITY (1, 1) NOT NULL,
[credentialID] INT DEFAULT (NULL) NULL,
[softwareName] NCHAR(30) NOT NULL,
[abbrevation] NCHAR(10) NOT NULL,
[uri] NVARCHAR(MAX) DEFAULT (NULL) NULL,
[version] NCHAR(15) DEFAULT (NULL) NULL,
[installPath] TEXT DEFAULT (NULL) NULL,
[samedir] BIT DEFAULT ((0)) NULL,
[subPathID] INT NULL,
PRIMARY KEY CLUSTERED ([requirementID] ASC),
CONSTRAINT [FK_RequirementsAnnotation_Credentials]
FOREIGN KEY ([credentialID])
REFERENCES [dbo].[Credential] ([credentialID]),
CONSTRAINT [FK_RequirementsAnnotation_SubPath]
FOREIGN KEY ([subPathID])
REFERENCES [dbo].[SubPath] ([subPathID])
控制台输出:
> SELECT TOP (1) [t0].[requirementID], [t0].[credentialID],
> [t0].[softwareName], [t0].[abbrevation], [t0].[uri], [t0].[version],
> [t0].[installPath], [t0].[samedir], [t0].[subPathID] FROM
> [dbo].[RequirementsAnnotation] AS [t0] WHERE [t0].[abbrevation] = @p0
> -- @p0: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [rml]
> -- Context: SqlProvider(Sql2008)
> Model: AttributedMetaModel Build: 4.0.30319.33440
>
> UPDATE [dbo].[RequirementsAnnotation] SET [abbrevation] = @p7 WHERE
> ([requirementID] = @p0) AND ([credentialID] = @p1) AND ([softwareName]
> = @p2) AND ([abbrevation] = @p3) AND ([uri] = @p4) AND ([version] = @p5)
> AND ([installPath] IS NULL) AND (NOT ([samedir] = 1)) AND
> ([subPathID] = @p6)
> -- @p0: Input Int (Size = -1; Prec = 0; Scale = 0) [4]
> -- @p1: Input Int (Size = -1; Prec = 0; Scale = 0) [1]
> -- @p2: Input NChar (Size = 30; Prec = 0; Scale = 0) [repeats ]
> -- @p3: Input NChar (Size = 10; Prec = 0; Scale = 0) [rml ]
> -- @p4: Input NVarChar (Size = 4000; Prec = 0; Scale = 0) [xyz]
> -- @p5: Input NChar (Size = 15; Prec = 0; Scale = 0) [20140131 ]
> -- @p6: Input Int (Size = -1; Prec = 0; Scale = 0) [2]
> -- @p7: Input NChar (Size = 10; Prec = 0; Scale = 0) [rmlas]
> -- Context: SqlProvider(Sql2008) Model: AttributedMetaModel
每次调用后都会出现此结果。