context.SubmitChanges() throw NullReferenceException.

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
Michael_Grønbæk
Posts: 7
Joined: Tue 21 Apr 2009 10:10

context.SubmitChanges() throw NullReferenceException.

Post by Michael_Grønbæk » Sun 28 Jun 2009 22:25

Hi devart team

Im using dotConnect 5.20.33 for Oracle 10.2g and cannot run the following code without getting a NullReferenceException:

context.Connection.Open();
ActionTagTypeEntity atte = new ActionTagTypeEntity
{
Id = 0,
ActionTagEntities = null,
ActionTagTypeName = "TEST 20090628 1255",
IsActive = 1,
IsDeleted = 0,
Version = DateTime.Now
};


context.ActionTagTypeEntities.InsertOnSubmit(atte);
context.SubmitChanges(ConflictMode.ContinueOnConflict);
context.Connection.Close();

My DDL for the DB is:
-------------------------

CREATE TABLE "MyUser"."ActionTagType" (
"Id" NUMBER(20),
"ActionTagTypeName" VARCHAR2(250) NOT NULL,
"IsDeleted" NUMBER(1) DEFAULT 0 NOT NULL,
"IsActive" NUMBER(1) DEFAULT 1 NOT NULL,
"Version" TIMESTAMP(6),
CONSTRAINT "pk_ActionTagTypeId" PRIMARY KEY ("Id"),
CONSTRAINT "un_TagName" UNIQUE ("ActionTagTypeName"))
TABLESPACE USERS
STORAGE (
INITIAL 64K
MAXEXTENTS UNLIMITED
)
LOGGING;

CREATE OR REPLACE TRIGGER "MyUser"."trg_InsertActionTagType"
BEFORE INSERT ON "MyUser"."ActionTagType" FOR EACH ROW
BEGIN
SELECT "seq_ActionTagType".NEXTVAL INTO :new."Id" FROM DUAL;
END;

CREATE TABLE "MyUser"."ActionTag" (
"Id" NUMBER(20),
"ActionTagTypeId" NUMBER(20) NOT NULL,
"ActionTagValue" VARCHAR2(250) NOT NULL,
"IsDeleted" NUMBER(1) DEFAULT 0 NOT NULL,
"IsActive" NUMBER(1) DEFAULT 1 NOT NULL,
"Version" TIMESTAMP(6) NOT NULL,
CONSTRAINT "fk_ActionTagTypeId" FOREIGN KEY ("ActionTagTypeId")
REFERENCES "MyUser"."ActionTagType"("Id"),
CONSTRAINT "pk_MeterActionTagId" PRIMARY KEY ("Id"),
CONSTRAINT "un_TagValue" UNIQUE ("ActionTagValue"))
TABLESPACE USERS
STORAGE (
INITIAL 64K
MAXEXTENTS UNLIMITED
)
LOGGING;

CREATE OR REPLACE TRIGGER "MyUser"."trg_InsertActionTag"
BEFORE INSERT ON "MyUser"."ActionTag" FOR EACH ROW
BEGIN
SELECT "seq_ActionTag".NEXTVAL INTO :new."Id" FROM DUAL;
END;

The Entity Developer 2.0.21 has been used in producing the LINQ DataContext for Oracle 10.2g

Also I am not able to utilize the Version timstamp on both Tables as Optimistic locking. I have enabled the property IsVersion on the database Version column. If I try to utilize the timestamp I get an Oracle error back saying that I cannot insert null into the column because the column is defined as NOT NULL. The Version property in the code is not null and actually holds a valid datetime value.

Please advice on how to utilize the InsertOnSubmit() api and further on how to make use of optimistic locking using timestamp.

Best regards,
Michael

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 30 Jun 2009 10:10

The problem with SubmitChanges is already fixed, the fix will be included in the new build.
As for Version columns, the setting of these columns in code is not a correct way to use these mechanism.
Create update triggers for these columns, setting the current_timestamp() value for them.
Take a look at the Optimistic Concurrency overview here:
http://msdn.microsoft.com/en-us/library/bb399373.aspx

Michael_Grønbæk
Posts: 7
Joined: Tue 21 Apr 2009 10:10

When will next build be available?

Post by Michael_Grønbæk » Tue 30 Jun 2009 10:17

Hi devat team,

Thanks for your reply.

When is next build scheduled for release?

Best regards,
Michael
AndreyR wrote:The problem with SubmitChanges is already fixed, the fix will be included in the new build.
As for Version columns, the setting of these columns in code is not a correct way to use these mechanism.
Create update triggers for these columns, setting the current_timestamp() value for them.
Take a look at the Optimistic Concurrency overview here:
http://msdn.microsoft.com/en-us/library/bb399373.aspx

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 30 Jun 2009 11:07

We plan to release the build this week.

Michael_Grønbæk
Posts: 7
Joined: Tue 21 Apr 2009 10:10

Calling two SP within same DataContext without SubmitChanges

Post by Michael_Grønbæk » Tue 30 Jun 2009 11:24

AndreyR wrote:We plan to release the build this week.
Will the following scenario also be covered by the next build?


I tried to call two different Stored Procedures from within the same DataContext using the same connection.

The first procedure spA() would insert a row into a table A and then return the newly created rowid from that call without doing any commit.

The second stored procedure spB() then would insert a row into a table B with the newly returned rowid from tabla A - as table B has a foreign key constraint on table A.

The above scenario does not work. It seem that if this is about to work out then spA() must make explicit commit so that spB() will be able to see the newly generated rowid generated inside table A.

The scenario does work inside Oracle itself - thus:
-----------------------------------------------------------------------

local_commit := 0;

"MyUser"."pkg_ActionTagType"."sp_InsertActionTagType"(id, 'ActionTagTypeName', local_commit, sp_res);

"MyUser"."pkg_ActionTag"."sp_InsertActionTag"(id, sp_res, 'ActionTagValue' , local_commit, sp_res);
COMMIT;

The two tables A & B makes use of sequences and triggers in order to autogenerate the rowid.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 30 Jun 2009 13:23

I recommend you to assign the stored procedures to Insert commands of your entities and then simply call
InsertOnSubmit() and later SubmitChanges() in the end of operations.
You can find some hints about mapping stored procedures in LINQ to SQL here.
http://msdn.microsoft.com/en-us/library/bb546186.aspx

Post Reply