我在使用活動記錄保存Subsonic 3中的記錄時遇到問題。我使用DAL和TTS生成了我的對象,因爲下面的測試通過,所以一切看起來都很好。我認爲我的連接字符串是正確的,否則代不會成功。使用活動記錄在Subsonic 3中保存記錄
[Test]
public void TestSavingAnEmail()
{
Email testEmail = new Email();
testEmail.EmailAddress = "[email protected]";
testEmail.Subscribed = true;
testEmail.Save();
Assert.AreEqual(1, Email.All().Count());
}
在現場側,下面的代碼失敗:
protected void btEmailSubmit_Click(object sender, EventArgs e)
{
Email email = new Email();
email.EmailAddress = txtEmail.Text;
email.Subscribed = chkSubscribe.Checked;
email.Save();
}
與消息:需要指定值或選擇查詢插入 - 不能去!在下面的行repo.Add(this,provider);在我的ActiveRecord.cs行:
public void Add(IDataProvider provider){
var key=KeyValue();
if(key==null){
var newKey=_repo.Add(this,provider);
this.SetKeyValue(newKey);
}else{
_repo.Add(this,provider);
}
SetIsNew(false);
OnSaved();
}
我在這裏做一些可怕的錯誤?保存和添加方法具有我認爲可以安全使用的無參數重載。我需要通過提供商嗎?我已經搜索了一段時間,並沒有拿出任何具體的情況。預先感謝您提供任何答案。
該表的模式是:
USE [xxxx]
GO
/****** Object: Table [dbo].[Emails] Script Date: 03/11/2010 13:15:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Emails](
[Id] [int] IDENTITY(1,1) NOT NULL,
[V_EmailAddress] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[B_Subscribed] [bit] NOT NULL,
[DT_CreatedOn] [datetime] NOT NULL,
[DT_ModifiedOn] [datetime] NOT NULL,
CONSTRAINT [PK_Emails] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
只有1代中的警告,那就是
Multiple template directives were found in the template. All but the first one will be ignored. Multiple parameters to the template directive should be specified within one template directive.
Settings.ttinclude
所以它似乎是在Sql2005Generator中的問題。我在該類中的插入對象的計數爲0,選擇值爲空,因此觸發異常。但至於爲什麼他們是零和空我不確定。 – singfoom 2010-03-10 20:12:47