Can not found Inserted Record?

Can not found Inserted Record?

Postby ying515_huang » Wed 06 Jun 2012 10:11

We inserted record when it is not SubmitChanges().
user want modify inserted record. but it is not found.
Code: Select all
        public void InsertLines(SmpWipmmtLinesVMeta data)
        {
            try
            {
                DateTime? db_date = db.GetDbSysDate();
                data.WmLineId = Convert.ToDecimal(db.GetWipmmtLinesNextval());
                data.WmHeaderId = this.hd_id;
                SmpWipmmtLinesTp dls = new SmpWipmmtLinesTp();
                copy_data(data, dls);
                db.SmpWipmmtLinesTps.InsertOnSubmit(dls);
                decimal i = 0;
                SmpWipmmtLinesTp target = db.SmpWipmmtLinesTps.Where(p => p.WmLineId == data.WmLineId).FirstOrDefault();
                if (target != null)  <-- why it is always null
                {
                    i = target.WmLineId;
                }
            }

SmpWipmmtLinesTp is database view!

ASP.NET MVC 2.0 & Visual 2010 & framework 4.0
Oracle DB 11
dotConnect Ver 6.10.111.0
ying515_huang
 
Posts: 13
Joined: Mon 21 Feb 2011 03:35

Re: Can not found Inserted Record?

Postby StanislavK » Thu 07 Jun 2012 13:34

When the InsertOnSubmit method is invoked, no actual interoperations with the database are performed. The new entity is saved to the database only when SubmitChanges is called. Thus, the new row is not available in the database yet when you execute the query.

On the other hand, the query is translated into SQL and executed at the server. As the server returns an empty result set, the query result is null.

Thus, the 'target' object should not be null only if you invoke SubmitChanges before querying.

Please tell us if anything is unclear.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48


Return to dotConnect for Oracle