【发布时间】:2010-03-09 23:33:55
【问题描述】:
我在使用 Active Record 保存 Subsonic 3 中的记录时遇到问题。我已经使用 DAL 和 tts 生成了我的对象,一切似乎都很好,因为以下测试通过了。我认为我的连接字符串是正确的,否则生成不会成功。
[Test]
public void TestSavingAnEmail()
{
Email testEmail = new Email();
testEmail.EmailAddress = "newemail@test.com";
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();
}
我在这里做错了什么吗? save 和 add 方法具有我认为可以安全使用的无参数重载。我需要通过提供者吗?我已经为此搜索了一段时间,但无法提出任何特定于我的情况的信息。提前感谢您的任何回答。
表的架构是:
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的问题。我在该类中的 Insert 对象的计数为 0,并且选择值为空,因此命中异常。但至于为什么它们是 0 和空的,我不确定。
标签: subsonic subsonic3 subsonic-active-record