When practicing with LightSpeed I can build an object on top of:
CREATE TABLE table1
(
table1_id serial NOT NULL,
"name" character varying(250) NOT NULL,
CONSTRAINT table1_pk PRIMARY KEY (table1_id)
)
WITH (
OIDS=FALSE
);
and it works fine. If using a view like this:
CREATE OR REPLACE VIEW view1 AS
SELECT table1.table1_id, table1.name
FROM table1;
CREATE OR REPLACE RULE "_RETURN" AS
ON SELECT TO view1 DO INSTEAD SELECT table1.table1_id, table1.name
FROM table1;
CREATE OR REPLACE RULE view1_i AS
ON INSERT TO view1 DO INSTEAD INSERT INTO table1 (table1_id, name)
VALUES (DEFAULT, new.name)
RETURNING table1.table1_id, table1.name;
These rules work well enough to insert records into table1 by inserting them into view1 using an SQL INSERT, but my model throws an exception when switched from table1 to view1:
Mindscape.LightSpeed.LightSpeedException was unhandled
Message="An error occurred when trying to assign a new Identity value to this entity. Check inner exception for details"
Source="Mindscape.LightSpeed"
StackTrace:
at Mindscape.LightSpeed.LightSpeedException.(Exception , String , Object[] )
at Mindscape.LightSpeed.Entity`1.SetIdInternal(Object )
at ..(Entity , )
at ..(Entity , ICollection`1 )
at ..(Entity , List`1 )
at ..(UnitOfWorkBase , IEnumerable`1 , IEnumerable`1 )
at Mindscape.LightSpeed.UnitOfWork.SaveChanges(Boolean reset)
at Mindscape.LightSpeed.UnitOfWorkBase.SaveChanges()
at TestPostgres1.Program.Main(String[] args) in C:\Users\s.rice\Documents\Visual Studio 2008\Projects\TestPostgres1\TestPostgres1\Program.cs:line 22
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.InvalidCastException
Message="Object cannot be cast from DBNull to other types."
Source="mscorlib"
StackTrace:
at System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at Mindscape.LightSpeed.Entity`1.SetIdInternal(Object )
InnerException:
Any idea why this is happening and how to stop it? Something of a showstopper at present.
Thanks!
Stephen