我在MS SQL Server 2008标准版中有下表:
CREATE TABLE [dbo].[NewTestQueue](
[JobID] [int] IDENTITY(1,1) NOT NULL,
[ServerName] [varchar](50) NULL,
[DomainID] [int] NOT NULL,
[Action] [varchar](50) NULL,
[Folder] [varchar](150) NULL,
[Method] [varchar](50) NULL,
[ActionProfile] [varchar](50) NULL,
[Title] [varchar](150) NULL,
[Suffix] [varchar](50) NULL,
[Host] [varchar](150) NULL,
[Url] [varchar](250) NULL,
[Expression] [varchar](50) NULL,
[MasterTest] [varchar](50) NULL,
[Completed] [bit] NOT NULL
) ON [PRIMARY]
我正在使用
SubSonic ActiveRecord
T4模板并具有以下代码:
var tests = NewTestQueue.Find(d => !d.Completed);
foreach(var test in tests)
{
test.Completed = true;
test.Update();
}
引发的异常是:
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="SubSonic.Core"
StackTrace:
at SubSonic.Extensions.Database.ToUpdateQuery[T](T item, IDataProvider provider)
at SubSonic.Repository.SubSonicRepository`1.Update(T item, IDataProvider provider)
at HostMonitor.NewTestQueue.Update(IDataProvider provider) in E:\AppsDev.NET\_UK_Minds\Tollon Components\HostMonitor\Tollon.HostMonitor.TestGenerator\ActiveRecord\ActiveRecord.cs:line 593
at HostMonitor.NewTestQueue.Update() in E:\AppsDev.NET\_UK_Minds\Tollon Components\HostMonitor\Tollon.HostMonitor.TestGenerator\ActiveRecord\ActiveRecord.cs:line 586
at Tollon.HostMonitor.TestGenerator.Program.Main(String[] args) in E:\AppsDev.NET\_UK_Minds\Tollon Components\HostMonitor\Tollon.HostMonitor.TestGenerator\Program.cs:line 46
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
为什么会这样?
更新:
我从Github中获取了最新的源代码,但现在它破坏了T4模板生成的代码。生成的
ActiveRecord.cs
不会编译并给出以下生成错误:
No overload for method 'Load' takes '1' arguments
[Path snipped]\subsonic-SubSonic-3.0-4748517\SubSonic.Tests\BugReports\Generated\ActiveRecord.cs
Line: 708
发生此错误的代码如下:
public void Load(IDataReader rdr) {
Load(rdr, true);
}
public void Load(IDataReader rdr, bool closeReader) {
if (rdr.Read()) {
try {
rdr.Load(this);
SetIsNew(false);
SetIsLoaded(true);
} catch {
SetIsLoaded(false);
throw;
}
}else{
SetIsLoaded(false);
}
if (closeReader)
rdr.Dispose();
}
我尝试了原始的3.0.0.3 ActiveRecord模板和来自
SubSonic.Tests
项目。