CREATE TABLE [dbo].[Table1](
[Id] [int] NOT NULL,
[TimeCreated] [datetime] NOT NULL,
CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
insert into table1(id, timecreated) values(1, getdate())
[Id] [int] NOT NULL,
[TimeCreated] [datetime] NOT NULL,
CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
insert into table1(id, timecreated) values(1, getdate())
Aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Cus.aspx.cs"
Inherits="RfqMan4.Cus" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataSourceID="LinqDataSource1" DataKeyNames="id">
<columns>
<asp:commandfield ShowEditButton="True"></
asp:commandfield>
<asp:boundfield DataField="id" HeaderText="id"
ReadOnly="True"
SortExpression="id"></asp:boundfield>
<asp:boundfield DataField="TimeCreated"
HeaderText="TimeCreated"
SortExpression="TimeCreated"></asp:boundfield>
</columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="RfqMan4.Components.RfqManDataContext"
EnableDelete="True"
EnableInsert="True" EnableUpdate="True"
TableName="Table1s">
</asp:LinqDataSource>
</div>
</form>
</body>
</html>
Inherits="RfqMan4.Cus" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataSourceID="LinqDataSource1" DataKeyNames="id">
<columns>
<asp:commandfield ShowEditButton="True"></
asp:commandfield>
<asp:boundfield DataField="id" HeaderText="id"
ReadOnly="True"
SortExpression="id"></asp:boundfield>
<asp:boundfield DataField="TimeCreated"
HeaderText="TimeCreated"
SortExpression="TimeCreated"></asp:boundfield>
</columns>
</asp:GridView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="RfqMan4.Components.RfqManDataContext"
EnableDelete="True"
EnableInsert="True" EnableUpdate="True"
TableName="Table1s">
</asp:LinqDataSource>
</div>
</form>
</body>
</html>
每次试图更新时都会抛出ChangeConflictException异常.
奇怪的是如果把第二个列换成除datetime以外的类型,比如int, nvarchar等都能正常工作; 而Northwind里同样包含datetime列的Orders表也没有问题.
已经证实了这个问题与Id列是否自增,datetime列是否可为空,是否有默认值无关--无论任何情况下都会出现.
这个是bug,还是我忘了哪一步?