Page 1 of 1

InsertOnSubmit

Posted: Thu 01 Nov 2012 15:46
by Glenn
Hi

I am using a DataContext build on Oracle 11g, I have a type called VSpsk and I need to put some new objects into my Table, like this

var vs = new Vspsk();
vs.Id = 1;
vs.Name = 2;
var ls = Context.GetTable<Vspsk>();
ls.InsertOnSubmit(vs);
var q = ls.FirstOrDefault(v => v.Id.Equals(1));

Why is q null at this point ?

I can see Context.ChangeSet.Inserts contains the object -
am I supposed to join myself ?

Or is there some other way to do this without calling the database ?


Best regards
Glenn

Re: InsertOnSubmit

Posted: Fri 02 Nov 2012 14:20
by MariiaI
If we correctly understood you, you want to be able to work with the new data for your table without sending it to the database (SubmitChanges() method), is it so?
This is the expected behavior: the query result is based mainly on the rows returned by the server; the LinqConnect runtime does not search for the suitable entities in the entity cache or among the entities marked for insertion.

Thus, in order to changes take effect and were sent to the database, you should call the SubmitChanges() method for your DataContext. The InsertOnSubmit() method assumes that all changes will be made on calling the SubmitChanges() method.
Please add the following line to your code:

Code: Select all

Сontext.SubmitChanges();
after

Code: Select all

ls.InsertOnSubmit(vs);
For more information please refer to:
http://www.devart.com/linqconnect/docs/ ... ubmit.html
http://www.devart.com/linqconnect/docs/ ... anges.html

Re: InsertOnSubmit

Posted: Mon 05 Nov 2012 10:09
by Glenn
Thank you, I understand. But I would like to be able to work with new records before they are sent to the database in an off-line context - is there any way to do that?

/Glenn

Re: InsertOnSubmit

Posted: Tue 06 Nov 2012 14:05
by MariiaI
The only way to access the new data before inserting them into the database - is to use DataContext.GetChangeSet() method.
Please refer to:
http://www.devart.com/linqconnect/docs/ ... geSet.html
http://msdn.microsoft.com/en-us/library ... geset.aspx