InsertOnSubmit

InsertOnSubmit

Postby Glenn » Thu 01 Nov 2012 15:46

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
Glenn
 
Posts: 3
Joined: Thu 25 Oct 2012 11:16

Re: InsertOnSubmit

Postby MariiaI » Fri 02 Nov 2012 14:20

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/InsertOnSubmit.html
http://www.devart.com/linqconnect/docs/Devart.Data.Linq~Devart.Data.Linq.DataContext~SubmitChanges.html
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: InsertOnSubmit

Postby Glenn » Mon 05 Nov 2012 10:09

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
Glenn
 
Posts: 3
Joined: Thu 25 Oct 2012 11:16

Re: InsertOnSubmit

Postby MariiaI » Tue 06 Nov 2012 14:05

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/Devart.Data.Linq~Devart.Data.Linq.DataContext~GetChangeSet.html
http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.getchangeset.aspx
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to dotConnect for Oracle