This question is locked. New answers and comments are not allowed.
I am trying to figure out if there is a better way to do this, because it seems I am duplicating some code for probably no reason.
Anyway, I am trying to figure out how to manage new objects versus editing existing objects.
If I edit an existing object, I can use the
However, here is my issue. If I have a new Customer (for example) and the primary key is ID (INT IDENTITY (1, 1)), when I create
and treat it like all the other objects to be changed/deleted.
However, when I do this, I get an error :
So, I have been having to track new objects separate from existing.
Is there a way to add objects without the error and only worry about the details right before the commit? If I don't commit, I don't see why I would get the error.
I would like to be able to treat all the objects the same, if possible.
Anyway, I am trying to figure out how to manage new objects versus editing existing objects.
If I edit an existing object, I can use the
.IsDirty, Rollback(), Commit(), etc, as well as the handlers (not that I use all of them at the moment) |
scope.Tracking.Added += new AddEventHandler(Add); |
scope.Tracking.Changing += new ChangeEventHandler(Changing); |
scope.Tracking.Changed += new ChangeEventHandler(Changed); |
scope.Tracking.Removing += new RemoveEventHandler(Removing); |
scope.Tracking.Removed += new RemoveEventHandler(Removed); |
scope.Tracking.Refreshing += new RefreshEventHandler(Refreshing); |
scope.Tracking.Refreshed += new RefreshEventHandler(Refreshed); |
However, here is my issue. If I have a new Customer (for example) and the primary key is ID (INT IDENTITY (1, 1)), when I create
Customer c = New Customer(); |
// I would like to do : |
scope.Add(c) |
and treat it like all the other objects to be changed/deleted.
However, when I do this, I get an error :
Insert of '749405200-' failed: Telerik.OpenAccess.RT.sql.SQLException: Cannot insert the value NULL into column 'FirstName', table 'Billys.dbo.Customer'; column does not allow nulls. INSERT fails. |
So, I have been having to track new objects separate from existing.
Is there a way to add objects without the error and only worry about the details right before the commit? If I don't commit, I don't see why I would get the error.
I would like to be able to treat all the objects the same, if possible.
12 Answers, 1 is accepted
0

IT-Als
Top achievements
Rank 1
answered on 31 Aug 2009, 08:00 AM
Hi Adam,
Are you getting this upon the call to Add() or on Transaction.Commit?
It seems like you are hitting a Commit or a Flush somewhere.
Check the configuration of the Customer class. Do you have the setting "Throw exception if null" set on the field firstname?
I don't remember if this setting is checked upon scope.Add.. I don't think so.
It should indeed be possible to have several scope.Add and then do a Commit as the last thing.
Regards
Henrik
Are you getting this upon the call to Add() or on Transaction.Commit?
It seems like you are hitting a Commit or a Flush somewhere.
Check the configuration of the Customer class. Do you have the setting "Throw exception if null" set on the field firstname?
I don't remember if this setting is checked upon scope.Add.. I don't think so.
It should indeed be possible to have several scope.Add and then do a Commit as the last thing.
Regards
Henrik
0

Adam
Top achievements
Rank 1
answered on 31 Aug 2009, 08:23 AM
I am getting this on the ADD, not the commit.
Here is the code:
I get the error on the Add
Not sure what else I can do... I do not see the throw exception anywhere in the generated class.
using BillysDAL; |
using Telerik.OpenAccess.Query; |
namespace CustomerModule.BAL |
{ |
public static class NewCustomer |
{ |
public static Person Instance() |
{ |
var query = from pt in CustomerModule.GetScope().Extent<PersonType>() |
where pt.Id == 2 |
select pt; |
Person p = new Person() {Active = true, DateModified=System.DateTime.Now}; |
p.XRefPersonPersonTypes.Add(query.FirstOrDefault()); |
return p; |
} |
} |
} |
Here is the code:
private void AddPerson() |
{ |
if (scope.Transaction.IsActive) |
{ |
scope.Transaction.Rollback(); |
} |
SelectedPerson = NewCustomer.Instance(); |
IsEditable = true; |
SelectedPerson.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(NewPersonChangedHandler); |
scope.Transaction.Begin(); |
scope.Add(SelectedPerson); |
} |
I get the error on the Add
[Telerik.OpenAccess.FieldAlias("firstName")] |
public string FirstName |
{ |
get { return firstName; } |
set |
{ |
OnPropertyChanging("FirstName"); |
this.firstName = value; |
OnPropertyChanged("FirstName"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("lastName")] |
public string LastName |
{ |
get { return lastName; } |
set |
{ |
OnPropertyChanging("LastName"); |
this.lastName = value; |
OnPropertyChanged("LastName"); |
} |
} |
Not sure what else I can do... I do not see the throw exception anywhere in the generated class.
0

IT-Als
Top achievements
Rank 1
answered on 31 Aug 2009, 08:52 AM
Hi Adam,
Is this a reversed mapped database? I guess so..
I cannot see why the scope.Add throws a datastore exception on the firstName column.. or why the datastore is getting hit during the Add (except for assigning the Id via AutoInc).
How is the Person class mapped. The primary key is not mistakenly set to be the firstname or field...or the firstname field is not mistakenly set to be part of the primary key in the mapping configuration?
My few cents.
Henrik
Is this a reversed mapped database? I guess so..
I cannot see why the scope.Add throws a datastore exception on the firstName column.. or why the datastore is getting hit during the Add (except for assigning the Id via AutoInc).
How is the Person class mapped. The primary key is not mistakenly set to be the firstname or field...or the firstname field is not mistakenly set to be part of the primary key in the mapping configuration?
My few cents.
Henrik
0
Hello Adam,
You should not be getting an exception during add. The exception you provided states that there is an error in the SQL. We generate SQL upon commit. Maybe you are doing a commit or flush? What you can do to avoid this is to define some default values in your constructor. If you are using reverse mapping you are getting an empty constructor. There you can specify for example:
This will enable you to execute
than your customer will be initzialized with default in the first name. This will prevent you from getting this exception. Later you can change that to a desired value. Note that if you execute this:
The custom logic in the constructor will be override.
Sincerely yours,
Petar
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
You should not be getting an exception during add. The exception you provided states that there is an error in the SQL. We generate SQL upon commit. Maybe you are doing a commit or flush? What you can do to avoid this is to define some default values in your constructor. If you are using reverse mapping you are getting an empty constructor. There you can specify for example:
firstName = "default"; |
Customer c = new Customer(); |
Customer c = new Customer(){ firstName = "Stan"}; |
Sincerely yours,
Petar
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0

Adam
Top achievements
Rank 1
answered on 31 Aug 2009, 02:22 PM
But if I set invalid default values (such as "default"),
a) It will show up in the TextBox
and
b) It will allow a save when it should not, or I have to check for "default", which seems like a hokey workaround.
Here is the table definition (and yes, it is reverse mapped)
and this is the generated class
and
a) It will show up in the TextBox
and
b) It will allow a save when it should not, or I have to check for "default", which seems like a hokey workaround.
Here is the table definition (and yes, it is reverse mapped)
SET ANSI_NULLS ON |
GO |
SET QUOTED_IDENTIFIER ON |
GO |
SET ANSI_PADDING ON |
GO |
CREATE TABLE [dbo].[Person]( |
[ID] [bigint] IDENTITY(1,1) NOT NULL, |
[Title] [varchar](50) NULL, |
[FirstName] [varchar](50) NOT NULL, |
[MiddleName] [varchar](50) NULL, |
[LastName] [varchar](50) NOT NULL, |
[Suffix] [varchar](50) NULL, |
[Active] [bit] NOT NULL, |
[DateModified] [datetime] NOT NULL, |
CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED |
( |
[ID] ASC |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] |
) ON [PRIMARY] |
GO |
SET ANSI_PADDING OFF |
GO |
ALTER TABLE [dbo].[Person] ADD CONSTRAINT [DF_Person_Active] DEFAULT ((1)) FOR [Active] |
GO |
ALTER TABLE [dbo].[Person] ADD CONSTRAINT [DF_Person_DateModified] DEFAULT (getdate()) FOR [DateModified] |
GO |
and this is the generated class
using System; |
using System.Collections.Generic; |
using System.ComponentModel; |
namespace BillysDAL |
{ |
// Generated by Telerik OpenAccess |
// Used template: c:\program files (x86)\telerik\sdk\IDEIntegrations\templates\PCClassGeneration\cs\templates\classgen\class\partialuserdefault.vm |
// NOTE: Field declarations and 'Object ID' class implementation are added to the 'designer' file. |
// Changes made to the 'designer' file will be overwritten by the wizard. |
public partial class Person : INotifyPropertyChanging, INotifyPropertyChanged |
{ |
//The 'no-args' constructor required by OpenAccess. |
public Person() |
{ |
} |
//INotifyPropertyChanging Members |
public event PropertyChangingEventHandler PropertyChanging; |
protected virtual void OnPropertyChanging(string propertyName) |
{ |
if (this.PropertyChanging != null) |
this.PropertyChanging(this, new PropertyChangingEventArgs(propertyName)); |
} |
//INotifyPropertyChanged Members |
public event PropertyChangedEventHandler PropertyChanged; |
protected virtual void OnPropertyChanged(string propertyName) |
{ |
if (this.PropertyChanged != null) |
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); |
} |
[Telerik.OpenAccess.FieldAlias("id")] |
public long Id |
{ |
get { return id; } |
set |
{ |
OnPropertyChanging("Id"); |
this.id = value; |
OnPropertyChanged("Id"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("active")] |
public bool Active |
{ |
get { return active; } |
set |
{ |
OnPropertyChanging("Active"); |
this.active = value; |
OnPropertyChanged("Active"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("dateModified")] |
public DateTime DateModified |
{ |
get { return dateModified; } |
set |
{ |
OnPropertyChanging("DateModified"); |
this.dateModified = value; |
OnPropertyChanged("DateModified"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("firstName")] |
public string FirstName |
{ |
get { return firstName; } |
set |
{ |
OnPropertyChanging("FirstName"); |
this.firstName = value; |
OnPropertyChanged("FirstName"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("lastName")] |
public string LastName |
{ |
get { return lastName; } |
set |
{ |
OnPropertyChanging("LastName"); |
this.lastName = value; |
OnPropertyChanged("LastName"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("middleName")] |
public string MiddleName |
{ |
get { return middleName; } |
set |
{ |
OnPropertyChanging("MiddleName"); |
this.middleName = value; |
OnPropertyChanged("MiddleName"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("suffix")] |
public string Suffix |
{ |
get { return suffix; } |
set |
{ |
OnPropertyChanging("Suffix"); |
this.suffix = value; |
OnPropertyChanged("Suffix"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("title")] |
public string Title |
{ |
get { return title; } |
set |
{ |
OnPropertyChanging("Title"); |
this.title = value; |
OnPropertyChanged("Title"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("xRefPersonAttribute")] |
public IList<PersonAttribute> XRefPersonAttributes |
{ |
get { return xRefPersonAttribute; } |
} |
[Telerik.OpenAccess.FieldAlias("xRefPersonPersonType")] |
public IList<PersonType> XRefPersonPersonTypes |
{ |
get { return xRefPersonPersonType; } |
} |
} |
} |
and
using System; |
using System.Collections.Generic; |
namespace BillysDAL |
{ |
// Generated by Telerik OpenAccess |
// Used template: c:\program files (x86)\telerik\sdk\IDEIntegrations\templates\PCClassGeneration\cs\templates\classgen\class\partialdesignerdefault.vm |
[Telerik.OpenAccess.Persistent(IdentityField = "id")] |
public partial class Person |
{ |
private long id; // pk |
private bool active; |
private DateTime dateModified; |
private string firstName; |
private string lastName; |
private string middleName; |
private string suffix; |
private string title; |
private IList<PersonAttribute> xRefPersonAttribute = new List<PersonAttribute>(); |
private IList<PersonType> xRefPersonPersonType = new List<PersonType>(); |
} |
} |
#region main class file contents |
/* |
using System; |
using System.Collections.Generic; |
using System.ComponentModel; |
namespace BillysDAL |
{ |
//Generated by Telerik OpenAccess |
public partial class Person : INotifyPropertyChanging, INotifyPropertyChanged |
{ |
//The 'no-args' constructor required by OpenAccess. |
public Person() |
{ |
} |
//INotifyPropertyChanging Members |
public event PropertyChangingEventHandler PropertyChanging; |
protected virtual void OnPropertyChanging(string propertyName) |
{ |
if (this.PropertyChanging != null) |
this.PropertyChanging(this, new PropertyChangingEventArgs(propertyName)); |
} |
//INotifyPropertyChanged Members |
public event PropertyChangedEventHandler PropertyChanged; |
protected virtual void OnPropertyChanged(string propertyName) |
{ |
if (this.PropertyChanged != null) |
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); |
} |
[Telerik.OpenAccess.FieldAlias("id")] |
public long Id |
{ |
get { return id; } |
set |
{ |
OnPropertyChanging("Id"); |
this.id = value; |
OnPropertyChanged("Id"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("active")] |
public bool Active |
{ |
get { return active; } |
set |
{ |
OnPropertyChanging("Active"); |
this.active = value; |
OnPropertyChanged("Active"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("dateModified")] |
public DateTime DateModified |
{ |
get { return dateModified; } |
set |
{ |
OnPropertyChanging("DateModified"); |
this.dateModified = value; |
OnPropertyChanged("DateModified"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("firstName")] |
public string FirstName |
{ |
get { return firstName; } |
set |
{ |
OnPropertyChanging("FirstName"); |
this.firstName = value; |
OnPropertyChanged("FirstName"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("lastName")] |
public string LastName |
{ |
get { return lastName; } |
set |
{ |
OnPropertyChanging("LastName"); |
this.lastName = value; |
OnPropertyChanged("LastName"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("middleName")] |
public string MiddleName |
{ |
get { return middleName; } |
set |
{ |
OnPropertyChanging("MiddleName"); |
this.middleName = value; |
OnPropertyChanged("MiddleName"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("suffix")] |
public string Suffix |
{ |
get { return suffix; } |
set |
{ |
OnPropertyChanging("Suffix"); |
this.suffix = value; |
OnPropertyChanged("Suffix"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("title")] |
public string Title |
{ |
get { return title; } |
set |
{ |
OnPropertyChanging("Title"); |
this.title = value; |
OnPropertyChanged("Title"); |
} |
} |
[Telerik.OpenAccess.FieldAlias("xRefPersonAttribute")] |
public IList<PersonAttribute> XRefPersonAttributes |
{ |
get { return xRefPersonAttribute; } |
} |
[Telerik.OpenAccess.FieldAlias("xRefPersonPersonType")] |
public IList<PersonType> XRefPersonPersonTypes |
{ |
get { return xRefPersonPersonType; } |
} |
} |
} |
*/ |
#endregion //main class file contents |
0

Adam
Top achievements
Rank 1
answered on 31 Aug 2009, 02:33 PM
Also, I don't understand how I could be accidentally doing a commit or flush, when I step through the debugger, I have:
scope.Transaction.Begin();
(checking the values, I have)
By the way, what are these settings... ?
No error. so I hit F11 to continue
it steps to this:
I see the problem...
Basically, on the stubbed procedure (not yet implemented)
It must be trying to do an internal commit or flush. I take out that line, and it works.
scope.Transaction.Begin();
(checking the values, I have)
AutomaticBegin false |
Concurrency OPTIMISTIC_NO_LOST_UPDATES // Could this be the problem? |
FailFast true |
RefreshReadObjectsInNewTransaction true |
RestoreValues false |
RetainValues true |
No error. so I hit F11 to continue
it steps to this:
private void Add(object sender, AddEventArgs args) |
{ |
IObjectId oid = scope.GetObjectId(args.PersistentObject); |
} |
"Cannot insert the value NULL into column 'FirstName', table 'Billys.dbo.Person'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated." |
Telerik.OpenAccess.Exceptions.DataStoreException was unhandled by user code |
Message="Insert of '749405200-' failed: Telerik.OpenAccess.RT.sql.SQLException: Cannot insert the value NULL into column 'FirstName', table 'Billys.dbo.Person'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated.\r\n at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()\r\n at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()\r\n at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)\nINSERT INTO [Person] ([Active], [DateModified], [FirstName], [LastName], [MiddleName], [Suffix], [Title]) VALUES (?, ?, ?, ?, ?, ?, ?)\nselect scope_identity()\n(set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: Cannot insert the value NULL into column 'FirstName', table 'Billys.dbo.Person'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated.\r\n at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()\r\n at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()\r\n at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)" |
Source="Telerik.OpenAccess" |
CanRetry=false |
StackTrace: |
at Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e) |
at Telerik.OpenAccess.RT.ExceptionWrapper.Throw() |
at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.handleException(Exception x) |
at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.getObjectId(Object pc) |
at OpenAccessRuntime.DataObjects.UnsynchronizedPMProxy.getObjectId(Object o) |
at Telerik.OpenAccess.RT.ObjectScope.GetObjectId(Object pc) |
at CustomerModule.ViewModels.PersonsViewModel.Add(Object sender, AddEventArgs args) in C:\Data\Projects\Clients\Billys\CustomerModule\ViewModels\PersonsViewModel.cs:line 648 |
at Telerik.OpenAccess.AddEventHandler.Invoke(Object sender, AddEventArgs e) |
at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.fireAdded(Object ev) |
at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.makePersistent(Object o) |
InnerException: Telerik.OpenAccess.RT.sql.SQLException |
Message="Cannot insert the value NULL into column 'FirstName', table 'Billys.dbo.Person'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated." |
Source="Telerik.OpenAccess.Adonet2" |
Description="SQLState=;Cannot insert the value NULL into column 'FirstName', table 'Billys.dbo.Person'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated." |
ErrorCode=515 |
Number=515 |
StackTrace: |
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute() |
at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute() |
at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes) |
InnerException: |
I see the problem...
Basically, on the stubbed procedure (not yet implemented)
private void Add(object sender, AddEventArgs args) |
{ |
IObjectId oid = scope.GetObjectId(args.PersistentObject); |
} |
It must be trying to do an internal commit or flush. I take out that line, and it works.
private void Add(object sender, AddEventArgs args) |
{ |
//IObjectId oid = scope.GetObjectId(args.PersistentObject); |
} |
0

Adam
Top achievements
Rank 1
answered on 31 Aug 2009, 03:00 PM
More issues,
I can get past the error, but now when I add the new object, how do I get it to track changes?
Triggers on editing an object, but does not on the new object.
I can get past the error, but now when I add the new object, how do I get it to track changes?
scope.Tracking.Changing += new ChangeEventHandler(Changing); |
scope.Tracking.Changed += new ChangeEventHandler(Changed); |
Triggers on editing an object, but does not on the new object.
0
Hi Adam,
Thank you for providing us with your code. I was finally able to see the problem. This exception is thrown because you are trying to get the ID of an object that has not been committed to the database yet. However, because Telerik OpenAccess ORM would know the ID of the object after committing the transaction, the GetObjectID method is doing internal flush in order to retrieve the ID of the object. Note that this is done only if you are using AutoInc for your ID. If you are using HighLow this will not occur.
Kind regards,
Petar
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Thank you for providing us with your code. I was finally able to see the problem. This exception is thrown because you are trying to get the ID of an object that has not been committed to the database yet. However, because Telerik OpenAccess ORM would know the ID of the object after committing the transaction, the GetObjectID method is doing internal flush in order to retrieve the ID of the object. Note that this is done only if you are using AutoInc for your ID. If you are using HighLow this will not occur.
Kind regards,
Petar
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0

Adam
Top achievements
Rank 1
answered on 01 Sep 2009, 10:17 AM
So, how would I check if the new object has been changed, if I don't use IObjectId oid = scope.GetObjectId(args.PersistentObject);
I am trying to determine the best way to handle all this.
If I add a Person, I want to be able to track as the user types into the lastname (or firstname) fields, so that I can enable and disable buttons as typing occurs, whether or not it is a new record.
So, for example, if someone types a single character into any TextBox field (on a new record), I might want to enable the button for Clear (reset/undo) to reset it back to the original state.
It seems to work fine on existing records.
What is HighLow, and where is this set? I am doing a reverse mapping and do not know of such a thing in SQL Server.
I am trying to determine the best way to handle all this.
If I add a Person, I want to be able to track as the user types into the lastname (or firstname) fields, so that I can enable and disable buttons as typing occurs, whether or not it is a new record.
So, for example, if someone types a single character into any TextBox field (on a new record), I might want to enable the button for Clear (reset/undo) to reset it back to the original state.
It seems to work fine on existing records.
What is HighLow, and where is this set? I am doing a reverse mapping and do not know of such a thing in SQL Server.
0

IT-Als
Top achievements
Rank 1
answered on 01 Sep 2009, 12:27 PM
Hi Adam,
So I guess, it is a client-side thing to determine whether it is a new object instance (record) or not.
One way to do it, is to check whether the object has an Id or not. Since the Id is assigned when the object is persisted, this will work even though it is not that fancy.
You could also use the IsNew and IsDirty methods of the scope to perform the check. See:
http://www.telerik.com/help/openaccess-orm/telerik.openaccess-telerik.openaccess.iobjectcontext-isnew.html
Regarding the HighLow stuff:
The HighLow key generator kan generate keys without (or nearly without) hitting the database as it serves a pool of Ids to be used for a given class instance. So each time an id is need it is pulled from the pool...when the pool runs out of Ids, it asks the database to provide a new pool of unused Ids..
Since you reverse mapped the database (and your tables are defined with AUTOINC), I guess you will not be able to use the highlow generator.
So I guess, it is a client-side thing to determine whether it is a new object instance (record) or not.
One way to do it, is to check whether the object has an Id or not. Since the Id is assigned when the object is persisted, this will work even though it is not that fancy.
You could also use the IsNew and IsDirty methods of the scope to perform the check. See:
http://www.telerik.com/help/openaccess-orm/telerik.openaccess-telerik.openaccess.iobjectcontext-isnew.html
Regarding the HighLow stuff:
The HighLow key generator kan generate keys without (or nearly without) hitting the database as it serves a pool of Ids to be used for a given class instance. So each time an id is need it is pulled from the pool...when the pool runs out of Ids, it asks the database to provide a new pool of unused Ids..
Since you reverse mapped the database (and your tables are defined with AUTOINC), I guess you will not be able to use the highlow generator.
0

Adam
Top achievements
Rank 1
answered on 01 Sep 2009, 05:43 PM
Well, perhaps you can walk me through this slowly....
If I have (simplifying code)
Person p = new Person();
scope.Add(p);
scope.Tracking.Changing += new ChangeEventHandler(Changing);
Or do I need to do something simple, like
if ((args.PersistentObject) is Person)
{
Person p = (Person)args.PersistentObject;
.... check p.id
or how do I get the actual object (new or changed) from the args?
If I have (simplifying code)
Person p = new Person();
scope.Add(p);
scope.Tracking.Changing += new ChangeEventHandler(Changing);
private void Changing(object sender, ChangeEventArgs args) |
{ |
What goes here to check IsNew / IsDirty??? How can I get the object if I am not able to call //IObjectId oid = scope.GetObjectId(args.PersistentObject); |
} |
Or do I need to do something simple, like
if ((args.PersistentObject) is Person)
{
Person p = (Person)args.PersistentObject;
.... check p.id
or how do I get the actual object (new or changed) from the args?
0
Accepted

IT-Als
Top achievements
Rank 1
answered on 01 Sep 2009, 11:32 PM
Your code:
Person p = new Person();
scope.Add(p);
scope.Tracking.Changing += new ChangeEventHandler(Changing);
private void Changing(object sender, ChangeEventArgs args) |
{ |
scope.IsNew(args.PersistentObject); scope.IsDirty(args,PersistentObject); |
} |
My code is in the brackets.
I don't where you subscribe to this Changing event...( in a form maybe), but it should be a place where the scope is accesible.